call_user_func_array与call_user_func [英] call_user_func_array vs. call_user_func

查看:60
本文介绍了call_user_func_array与call_user_func的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天遇到了一个有趣的问题。我们有一个利用Zend Frameworks缓存功能的应用程序。对此应用程序的请求通常使用以下行来调用工厂方法

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));

这个想法是从工厂方法返回一个对象,稍后我们可以访问它。当我们实现缓存功能时,此调用就死了。没有错误,只有白色的屏幕。错误日志中没有任何内容。我们可以在ok之前对行进行错误记录,但是尝试在factory方法内进行error_log则无济于事。

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);

解决了该问题。

我们花了几个小时来查找错误报告,但并没有想出太多来解释这种行为。有人在想吗?

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

推荐答案

我遇到了这样的问题,当通过调用尚未加载的类时,__autoload不能正确触发一个PHP命令。据我所知,除了愚蠢的尝试和错误之外,没有其他策略,只要尝试一下在PHP命令为您解决之前是否明确调用该类的行即可。

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);

这篇关于call_user_func_array与call_user_func的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆