草庐IT

function-declaration

全部标签

php - 如何解决 Call to a member function notify() on array? (拉拉维尔 5.3)

我的听众是这样的:data->notify(New\App\Notifications\CheckoutOrder($event->data));}}如果我运行dd($event),结果是这样的:执行时出现错误:Calltoamemberfunctionnotify()onarray如何解决? 最佳答案 您需要使用notify()在具有Illuminate\Notifications\Notifiable特征的模型上,但绝对不在数组上。例如,你可以先获取一个User的实例:$user=User::where('email',$eve

php - register_shutdown_function() - 什么是最佳实践?

我目前出于多种目的使用register_shutdown_function()。一种用途是处理fatalerror,另一种用途是记录执行期间使用的资源,如时间、内存使用情况等。目前我注册了两个不同的关闭函数,但在一个测试中只有第一个运行而另一个似乎失败了。现在这当然可以由函数本身的一些错误触发,所以我重写了它,但是是否有可能是使用多个register_shutdown_function调用引起的错误?那么这里的最佳实践是什么,是注册两个不同的函数,还是只调用一个处理不同任务的函数?如果发生fatalerror,让函数加载错误处理类是否也安全(并且可能),还是我应该将功能保留在函数本身中

PHP/SQLite3 : Fatal error: Call to undefined function sqlite_num_rows()

当我调用函数sqlite_num_rows时出现此错误。它一定不是依赖性问题,因为其他Sqlite函数正在运行。我能够打开连接并从数据库获取数据。 最佳答案 晚了4年,但我遇到了同样的问题,所以这是我为遇到同样问题的任何人提供的解决方案//$dbisthedatabasehandle$result=$db->query("SELECT*FROMtable_name");$rows=0;//setrowcounterto0while($row=$result->fetchArray()){$rows+=1;//+1tothecount

php - 拉维尔 5.2 : Creating a custom route function - extending route

基本上,我想创建自己的Route::custom函数。这是因为我一直在为整个站点的多个路由使用相同的组和中间件(我还使用带有子域的模块,所以我们正在谈论为每个路由节省5-6行代码)我只想让Route::custom调用两个或三个其他Route函数。例如:Route::Module('forum')替换为Route::group(['middleware'=>['web','auth'],'domain'=>'forum.'.env('SITE_DOMAIN','example.com')],function(){Route::group(['middleware'=>'permissi

php - Laravel 5.2 curl_init() 抛出错误 "Call to undefined function"

我正在尝试使用curl在laravel中使用FCM,但出现错误。首先,我在我的一个Controller中编写了一个php代码:$first_name=$request->input('first_name');//FCMapiURL$url='https://fcm.googleapis.com/fcm/send';//api_keyavailableinFirebaseConsole->ProjectSettings->CLOUDMESSAGING->Serverkey$server_key='AIzaSyA1RyuAGGPASh_flFCwiyd9ZHEMYlhQOho';$tar

php - Symfony 3.3 从 3.2 : Compile Error: Cannot declare class Symfony\Bundle\SecurityBundle\Security\FirewallMap

自从我从symfony3.2更新到3.3后我遇到了一些问题,我得到了这个错误CompileError:CannotdeclareclassSymfony\Bundle\SecurityBundle\Security\FirewallMap,becausethenameisalreadyinuseinclasses.php(line1709)inClassCollectionLoader.php(line99)atClassCollectionLoader::load()inKernel.php(line428)atKernel->doLoadClassCache()inKernel.p

PHP 面向对象 : Get all declared classes which are have extended another parent class

我需要获取所有扩展了另一个父类的声明类。例如……classParentClass{}classChildOneextendsParentClass{}classChildTwoextendsParentClass{}classChildThree{}我需要一个输出这个的数组:array('ChildOne','ChildTwo')我是PHPOOP的新手,但基于一些谷歌搜索,我想到了这个解决方案。$classes=array();foreach(get_declared_classes()as$class){if(is_subclass_of($class,'ParentClass'))

php - 为什么我们需要 function_exists?

为什么我们需要检查用户定义函数的function_exists?内部或核心PHP函数看起来没问题,但如果用户知道并自己定义了一个函数,那么为什么还需要检查它是否存在?下面是自定义的用户定义函数if(!function_exists('bia_register_menu')){functionbia_register_menu(){register_nav_menu('primary-menu',__('PrimaryMenu'));}add_action('init','bia_register_menu');}谢谢 最佳答案 确保

php - MIME在PHP Mail Function Header中的作用是什么

有人能告诉我MIME-Version:1.0在phphtmlmail()函数中的作用是什么,为什么我们要使用它?我已经搜索过了,但找不到一个清晰的解释?//Alwayssetcontent-typewhensendingHTMLemail$headers="MIME-Version:1.0"."\r\n";$headers.="Content-type:text/html;charset=UTF-8"."\r\n";谢谢 最佳答案 mime版本在理论上允许对mime引入更新,但在实践中它没有被使用,并且总是设置为1.0。因为根据mi

PHPUnit RabbitMQ : write test for create connection function

我面临以下问题。我写了一个函数,它在给定所需参数的情况下创建一个连接对象(AMQPConnection)。现在想写相应的单元测试。如果没有运行RabbitMQ代理,我只是不知道该怎么做。这是有问题的功能:publicfunctiongetConnection($hostKey,array$params){$connection=null;try{$connection=newAMQPConnection($params['host'],$params['port'],$params['username'],$params['password'],$params['vhost']);//