Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call_user_func_array vs. call_user_func

I ran across an interesting issue today. We have an application that utilizes Zend Frameworks caching functionality. A request to this application typically calls a factory method using the following line

$result =  call_user_func_array(array("myclass", "factory"), array($id));

The idea is to return an object from the factory method that we can access later on. When we implemented a caching feature, this call just, well, dies. No errors, just a white screen. Nothing in the error log. We can error log the line before ok, but trying to error_log inside the factory method does nothing.

Interestingly enough, changing the line to :

$result =  call_user_func(array("myclass", "factory"), $id);

fixes the issue.

We've spent a few hours looking around for bug reports and haven't come up with much to explain this behavior. Thoughts anyone?

like image 440
goose77 Avatar asked Jul 13 '09 17:07

goose77


1 Answers

I have had issues like this that came down to __autoload not firing properly when a not-yet-loaded class was invoked through a PHP command. No other strategy than dumb trial and error for it as far as I know, just try if a line explicitly invoking the class before the PHP command solves it for you.

$dummy = new MyClassName;
call_user_func_array(array('MyClassName', 'method'), array($id));
unset($dummy);
like image 156
dyve Avatar answered Oct 21 '22 15:10

dyve