[TYPO3-core] RFC #7357: Use exceptions to detect missing user function

Martin Kutschker martin.kutschker-n0spam at no5pam-blackbox.net
Sat Feb 2 16:55:10 CET 2008


Oliver Klee schrieb:
> Hi,
> 
> -1 as this patch still has a few smaller issues and is in bad need of a
> refactoring. Please change these things and provide an updated patch.
> 
> +	public static function
> callUserFunction($funcName,&$params,&$ref,$checkPrefix='user_',$errorMode=0)
> {
> 
> Please use a space instead of a tab before the {.
> Please put spaces after the commas.
> 
> 
> +			if ($errorMode == 2) {
> +				throw new Exception($errorMsg);
> +			} elseif(!$errorMode)	{
> +				debug($errorMsg, 1);
> +			}
> 
> Please use a space before the (.

I'm still in the habit of the old code. For TYPO3 I'm adding those tabs 
for a while (years!) now. Have patience.

> Please use ($errorMode == 0) instead of (!$errorMode) because this will
> make the code a lot easier to read (I nearly gave you a -1 because the
> new code didn't seem to match the new function documentation).

I did this on purpose. See my decription: "To be compatible any true 
value except 2 means silent. "

  > Please use single quotes instead of double quotes (and use string
> appending with . to have the variables included).

Wow, so much more readable now:

'Function/class \''.$funcRef.'\' was ..'

I think we use ' way too strict. There are merits in the "foo $var bar" 
syntax. I only oppose "foo novar bar" as it triggers string parsing 
without any benefits (hence wasting CPU cycles).

> Actually, we now have this code three times - this is a bad smell.
> Please refactor it to a separate function.

What do you suggest? Add a private static function to t3lib_div for that 
purpose? Or maybe an inline function within callUserFunction() is more 
to your taste?

> 
> -				if (!$silent)	debug("<strong>ERROR:</strong> No function named:
> ".$funcRef,1);
> +				$errorMsg = "<strong>ERROR:</strong> No function named: ".$funcRef;
> +				if ($errorMode == 2) {
> +					throw new Exception($errorMsg);
> +				} elseif(!$errorMode)   {
> +					debug($errorMsg, 1);
> +				}
> 
> Ditto (the 4th time).

And so was BTW the old "if (!$silent) debug()" code.

Masi


More information about the TYPO3-team-core mailing list