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

Issue Type: Improvement Created: 2011-05-01T12:51:45.000+0000 Last Updated: 2011-05-10T21:09:39.000+0000 Status: Resolved Fix version(s): - 1.11.7 (02/Jun/11)

Reporter: Sergio Vaccaro (hujuice) Assignee: Marc Bennewitz (private) (mabe) Tags: - Zend_Cache

Related issues: Attachments:


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.

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

Regards, Sergio


Posted by Marc Bennewitz (private) (mabe) on 2011-05-03T21:26:52.000+0000

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.

Posted by Sergio Vaccaro (hujuice) on 2011-05-08T09:11:12.000+0000

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.

<pre class="highlight">
$obj = new cachedClass();

<pre class="highlight">
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:

<pre class="highlight">
$obj = new NONcachedClass();
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

Posted by Marc Bennewitz (private) (mabe) on 2011-05-09T21:53:52.000+0000

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

Posted by Sergio Vaccaro (hujuice) on 2011-05-10T14:12:28.000+0000

IMO, it would be an improvement. Sergio

Posted by Marc Bennewitz (private) (mabe) on 2011-05-10T21:09:39.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.