jjzjj

call_user_func

全部标签

php - 如何传递对 call_user_func 的引用?

考虑以下示例:functionmyTest(&$var){$var++;echo"var={$var}\n";}$x=42;call_user_func('myTest',$x);它显示警告:Warning:Parameter1tomyTest()expectedtobeareference,valuegivenin/home/alain/workspace/echo/echo.php(57):eval()'dcodeonline7注意:在在线沙箱上编写的代码,解释了评估。知道如何传递对call_user_func系列函数的引用吗?

PHP:函数名称中的变量

我想触发一个基于变量的函数。functionsound_dog(){return'woof';}functionsound_cow(){return'moo';}$animal='cow';printsound_{$animal}();**行是不正确的行。我以前做过这个,但是我找不到了。我知道潜在的安全问题等。有人吗?非常感谢。 最佳答案 你可以这样做,但必须先插入字符串:$animfunc='sound_'.$animal;print$animfunc();或者,使用

PHP forward_static_call 与 call_user_func

forward_static_call和call_user_func有什么区别?同样的问题适用于forward_static_call_array和call_user_func_array 最佳答案 不同之处在于,forward_static_call不会重置“被调用的类”信息,如果在类层次结构中上升并显式命名一个类,而call_user_func会重置信息这些情况(但如果使用parent、static或self仍然不会重置它)。例子:<?phpclassA{staticfunctionbar(){echoget_called

php - call_user_func(array(self, 'method' )) - 我必须给类(class)命名吗?

在PHP中,call_user_func(array(self,'method_name'))不起作用。self关键字不能在该上下文中使用。我实际上需要包含类的名称call_user_func(array('class_name','method_name'))。但是,如果我不在静态函数中,$this变量会在该上下文中起作用。为什么不同? 最佳答案 如果您想要当前类上下文的名称,请使用get_class()(不带任何参数)或__CLASS__。你已经写出了差异;self是一个关键字,不能用作数组中的引用(在PHP中应该是哪种类型?)

php - 相当于 PHP 的 call_user_func() 的 javascript

有没有人知道有没有?我想使用变量名调用一个函数。编辑:我在这里发布了一个关于我正在尝试做的事情的fiddle:http://jsfiddle.net/sAzPA/<divid="some">...</div>js:(function($){$.fn.MyPlugin=function(){returnthis.each(function(){varsomefunction=function(arg1,arg2){alert(arg1);},someotherfunction=function(arg1,arg2){alert(arg2);},re

Php(eval vs call_user_func vs 变量函数...)

尽管有一些关于这个问题的讨论,但我想通过某些示例检查什么是最好的方法。我没有使用现有的解决方案,而是创建了自己的持久层(就像许多人所做的那样)所以我的方法在这里也有问题。对于db中的每个表,我都有模型类,它具有适当的getter和setter以及一些强制性方法。我还只创建了一个通用的DAO类来处理所有类型的模型对象。因此,例如,为了保存任何模型对象,我实例化了genericDAO类并调用了将模型对象作为属性传递的保存方法。问题是在运行时genericDAO类不知道它获取了哪个模型对象以及其中存在哪些方法(getter和setter),所以我需要调用强制模型类方法来检索属性列表作为多个字

PHP 调用时传递引用是不可避免的吗?

给定以下界面:interfaceISoapInterface{publicstaticfunctionregisterSoapTypes(&$wsdl);publicstaticfunctionregisterSoapOperations(&$server);}以及以下代码:$soapProvider=array("FilePool","UserList");foreach($soapProvideras$provider){call_user_func(array($provider,"registerSoapTypes"

PHP call_user_func & $class->$func() 函数

转发功能一:$class->$func()功能二://Simplecallbackcall_user_func($func)//Staticclassmethodcallcall_user_func(array($class,$func))//Objectmethodcall$class=newMyClass();call_user_func(array($class,$func));有区别吗?我想查看源代码(https://github.com/php/php-src)我们应该怎么做? 最佳答案 call_user_func

php - 在 PHP 中执行纯匿名函数

与Javascript提供这种可能性的方式类似,在PHP中执行匿名函数的建议方法是什么?Javascript:(function(){console.log('Hello!');})();在PHP中尝试相同的操作会产生参数左括号的语法错误。我通过“误用”call_user_func()找到了解决此问题的方法:PHP:call_user_func(function(){echo"Hello!";});但是PHPdocumentation(更新:文档的德语版本)明确指出call_user_func()的第一个参数应该是一个字符串...所以我不确定我的解决方案

php - 对象通过引用传递。 call_user_func 的参数不是。是什么赋予了?

在PHP中,objectsareeffectivelypassedbyreference(引擎盖下发生的事情是abitmorecomplicated)。同时,call_user_func()的参数不通过引用传递。那么像这样的一段代码会发生什么?classExample{functionRunEvent($event){if(isset($this->events[$event])){foreach($this->events[$event]as$k=>$v){//call_user_func($v,&$this);//Theabovelineisworking
12