草庐IT

EXPECT_CALL

全部标签

php - 在同一个类中调用 __call 而不是 __callstatic,而不是调用另一个类

我有一个关于奇怪行为的问题。看这段代码:classUser{publicfunctioncan($name){returncall_user_func(array($name,'test'));}publicstaticfunction__callStatic($name,$args){return'User::__callStatic';}publicfunction__call($name,$args){return'User::__call';}}classFoo{publicstaticfunction__callStatic($name,$args){return'Foo::

php - 尝试在 Laravel 中的 Application::create() 中使用自定义外观导致 'Call to undefined method'?

我正在尝试为搜索功能创建自己的自定义外观,但遇到了一点困难:type:Symfony\Component\Debug\Exception\FatalErrorExceptionmessage:CalltoundefinedmethodIlluminate\Foundation\Application::create()file:H:\myproj\vendor\laravel\framework\src\Illuminate\Container\Container.phpline:165此错误是由于我的代码命中:Search::indexObject();我的Searchfacade设

php - Laravel 验证 : Call to a member function fails() on null

这段代码几天前还可以工作,但我似乎做了一些事情导致它崩溃了。我有这条路线:Route::post('admin/routemanagement','AdminController@addRoute');看起来像这样:publicfunctionaddRoute(Request$request){if(Auth::check()){$rules=['flightDep'=>'required','flightArr'=>'required','flightDepTime'=>'required','flightArrTime'=>'required',];$messages=['flig

php - Mysqli 更新抛出 Call to a member function bind_param() 错误

这个问题在这里已经有了答案:Whattodowithmysqliproblems?Errorslikemysqli_fetch_array():Argument#1mustbeoftypemysqli_resultandsuch(1个回答)关闭3年前。我有一个70/80的字段表单,我需要将其插入到一个表中,所以我没有手动创建一个巨大的插入语句,而是首先根据表单中的输入名称在我的数据库中创建了一个表,这里是代码我用来创建/更改表的functioncreateTable($array,$memberMysqli){foreach($arrayas$key=>$value){//echo"K

php - 相对命名空间和 call_user_func()

代码胜于Eloquent:namespaces.php:namespace_test.php:如评论所述,如果我在call_user_func()中使用完全限定名称,它会按预期工作,但如果我使用相对namespace,它会说找不到该类——但直接实例化有效。我是不是遗漏了某些东西或它的设计怪异? 最佳答案 您必须在回调中使用完全限定的类名。参见Example#3call_user_func()usingnamespacename我相信这是因为call_user_func是一个来自全局范围的函数,也从全局范围执行回调。不管怎样,请看第一

php - 如果 call_user_func 应该返回 false 怎么办?

我用call_user_func调用的函数应该返回FALSE。那么,如果可调用对象无效,我该如何检测错误呢?(旁注:为什么他们没有抛出异常而不是返回错误代码?或者有没有办法“捕获”错误?我有一个错误句柄。我应该让它为我抛出异常吗?) 最佳答案 如果要检查要调用的函数或方法是否真的存在,可以使用is_callable在打电话之前call_user_func.您可以将整个内容包装在一个函数中以便于重用:functioncall_uf($fn){if(is_callable($fn)){returncall_user_func($fn);

php - 在 PHP 7.0 中 fatal error : Uncaught Error: Call to undefined function json_encode()

我的服务器配置:[root@server~]#php-vPHP7.0.22(cli)(built:Aug7201716:18:27)(NTS)[root@server~]#nginx-vnginxversion:nginx/1.10.2操作系统:CentOS7.3.1611(核心)我的YUM安装详情:[root@server~]#yumlistinstalled|grepphpphp70u-cli.x86_647.0.22-2.ius.centos7@iusphp70u-common.x86_647.0.22-2.ius.centos7@iusphp70u-fpm.x86_647.0.

PHP5.3 : "Call to undefined method" error when calling invoke from class variable

我一直在用__invoke魔术方法做一些测试(以替换旧代码),但我不确定这是否是错误:假设我们有一个类:classCalc{function__invoke($a,$b){return$a*$b;}}以下是可能的并且没有任何问题:$c=newCalc;$k=$c;echo$k(4,5);//outputs20但是如果我想要另一个类来存储该对象的实例,这不起作用:classTest{public$k;function__construct(){$c=newCalc;$this->k=$c;//Justtoshowasimilarsituationthanbefore//$this-k=n

PHP fatal error : Call to undefined function when function is defined

我在PHP中遇到错误:PHPFatalerror:CalltoundefinedfunctiongetCookie代码:include('Core/dAmnPHP.php');$tokenarray=getCookie($username,$password);在dAmnPHP.php中,它在类dAmnPHP中包含一个名为getCookie的函数。当我运行我的脚本时,它告诉我该函数未定义。我做错了什么? 最佳答案 看起来您需要先创建该类的一个新实例,然后才能使用它的功能。尝试:$dAmn=newdAmnPHP;$dAmn->getC

PHP fatal error : Call to a member function find() on a non-object however my function work

我在代码的第71行收到此错误,但是该行的功能已正确执行,并且按照我的预期执行。但是,我注意到我的错误日志中充满了这些行:[09-Dec-201314:54:02UTC]PHPFatalerror:Calltoamemberfunctionfind()onanon-objectin/home/sportve/public_html/open_event_common.phponline71我检查的内容:simple_html_dom_parser已包含在内,第71行打算执行的此功能正在运行。这是我的代码的第71行:$content->find('a.openevent',0)->inne