Issues

ZF-11337: Zend_Cache_Frontend_Class::__call shoud throw an Exception on invalid method

Description

When the __call function is called, a call_user_func_array function is invoked, wrapped in a try/catch. But the call_user_func_array function returns a warning (not an exception) with an non-existent method name, blocking a good tracing.

I think that the line 223 (1.11.5) should be out of the try/catch and provide an exception itself in case of errors.


if (!$return = call_user_func_array(array($this->_cachedEntity, $name), $parameters))
   throw new Exception ('Unable to call ' . $name . ' bla bla bla');

Regards, Sergio

Comments

We don't know what the return value of the called function/method should be. A value of FALSE can be valid, too! If you call the method without the class cache you are going in the same error. -> The class cache is only for caching method results and not for adding features or changing functionalities.

What I meant is a bit different. The problem is to find a wrong call. An example could be the clearest explanation.

I have a class, successfully cached. After a while, I delete a method or change its name. Or maybe some coder mistyped the method name. How to find that wrong call? (Ok, there are many solutions).

When a wrong chunk of code calls the cached class, I have an error message generated by 'call_user_function' in Zend_Cache_Frontend_Class, but this way I'm not able to find where the wrong calling code is.


$obj = new cachedClass();
$obj->deletedOrMistypedMethod();

Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'cachedClass'
does not have a method 'deletedOrMistypedMethod' in
/path/to/lib/ZendFramework-1.11.6/library/Zend/Cache/Frontend/Class.php on line 223

This is not so helpful.

If I skip caching, this kind of error is a fatal error with a file/number reference:


$obj = new NONcachedClass();
$obj->deletedOrMistypedMethod();
Fatal error: Call to undefined method NONcachedClass::deletedOrMistypedMethod() in
/path/to/file/containing/the/wrong/code.php on line nn

This is why I thought to an exception.

Best regards, Sergio

I'll add an is_callable check and throw an exception like Zend_Cache_Frontend_Function

IMO, it would be an improvement. Sergio

implemented in r24031 (trunk) & r24032 (1.11 branch)