草庐IT

magic-methods

全部标签

php - 如何调用php中不存在的类方法?

我只想创建函数,就像magento中的getFieldname()一样。例如:在Magento中getId()-返回ID字段的值getName()-返回Name字段的值我怎样才能创建这样的功能?在这种情况下请帮助我..我想像下面的代码那样做,ClassCalled{$list=array();function__construct(){$this->list["name"]="vivek";$this->list["id"]="1";}functionget(){echo$this->list[$fieldname];}}$instance=newCalled();$instance-

PHP : Laravel - Array push after using eloquent pluck method

这是我的查询$RecipientList=Employees::select(DB::Raw('CONCAT(first_name,"",last_name)asemployee_name'),'email')->pluck('employee_name','email');它给我想要的正确结果,但是在我执行查询之后,我还有1个键=>值对要插入结果数组。如果我打印当前结果,它是这样的。Illuminate\Support\CollectionObject([items:protected]=>Array([punit@*****.com]=>PunitGajjar[milan@****

php - Laravel“类型错误 : While Updating Records with PUT/PATCH Methods

当我运行更新Controller时,它给了我这个错误,我尝试了来自同一个平台的不同解决方案,但他们的解决方法是使用单独的save($product)语法进行更新。我正在使用模型商店进行身份验证和保存数据或编辑删除。"Typeerror:Argument1passedtoIlluminate\Database\Eloquent\Relations\HasOneOrMany::save()mustbeaninstanceofIlluminate\Database\Eloquent\Model,arraygiven,calledinC:\xampp\htdocs\shopping\app\H

php - 如何使 __set 也适用于 PHP 中的静态操作?

当我调用self::$parameter=1;时,__set没有被调用。有解决办法吗? 最佳答案 来自manual:Propertyoverloadingonlyworksinobjectcontext.Thesemagicmethodswillnotbetriggeredinstaticcontext.Thereforethesemethodsshouldnotbedeclaredstatic.AsofPHP5.3.0,awarningisissuedifoneofthemagicoverloadingmethodsisdecla

PHP 面向对象 : Unique method per argument type?

我正在编写一个小的自制ORM(学术兴趣)。我正在尝试将TDD概念作为一项培训练习,并且作为该练习的一部分,我在开发类(class)时为API编写文档。恰当的例子-我正在研究经典的“getCollection”类型映射器类。我希望它能够为特定用户检索AssetsX的集合(比方说博客文章),以及基于任意数值数组的集合。所以-你可能有像其中任何一个这样的方法$User=$UserMapper->load(1);$ArticleCollection=$ArticleMapper->getCollection(range(10,20));$ArticleCollection=$ArticleMa

php - 类型提示 : method should accept any $arg that is an object

我有一个“集合”类,它有一个添加方法。add方法应该只接受对象。所以这是期望的行为:$x=5;//arbitrarynon-object$obj=newFoo;//arbitraryobject$collection=newCollection;$collection->add($obj);//shouldbeacceptablearg,nomattertheactualclass$collection->add($x);//shouldthrowanerrorbecause$xisnotanobject根据PHP手册,可以通过在$arg前面加上类名来键入提示方法。因为所有PHP类都是

php - AWeber API "Method requires access to Subscriber information"错误故障排除

我正在尝试使用PHPSDK从AWeber列表中检索特定订阅者。代码:$subscribers=$account->loadFromUrl("/accounts/$account->id/lists/$list_id/subscribers");var_dump($subscribers->find(array('email'=>$email)));exit;问题是,我收到以下错误:WebServiceError:MethodrequiresaccesstoSubscriberinformation.Google空手而归。 最佳答案

aop - FLOW3 需要将 PHP 设置 "magic_quotes_gpc"设置为关闭。 (错误#1224003190)

在mac上配置FLOW3时,我根据设置magic_quotes_gpc=off修改了php.ini并且在重新启动服务器时我得到了magic_quotes_gpc=off通过浏览http://localhost:8888/MAMP/phpinfo.php但是在运行时:$./flow3kickstart:packageAcme.Demo我收到以下错误消息:FLOW3requiresthePHPsetting"magic_quotes_gpc"settoOff.(Error#1224003190)谁能知道它出了什么问题? 最佳答案 您通过

php - call_user_method_array 函数已弃用,用什么代替它?

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:Recommendedreplacementfordeprecatedcall_user_method?FunctioninPHPdeprecated,whatshouldIusenow?call_user_method_array函数已弃用,那么我应该使用什么来实现相同的结果?

php - 从不同的 "method of a class"调用递归 "method of the same class"

我问了thisquestionbefore,有人放了一个链接来向我解释什么是递归函数。他/她投了反对票等等,就像在真正的递归函数中一样,所有其他人也投了反对票。现在我再问,我应该如何从不同的“同一类的方法”调用一个递归的“一个类的方法”em>?在第一个“递归方法”的定义中进行递归时,我应该使用$this->method()还是只使用method()谢谢;)(我称它为类的方法,以避免那些因为说“功能”而用否定杀死的人) 最佳答案 您以与调用任何其他方法相同的方式递归调用一个方法——只是您在其自身内部调用该方法。例如,请看以下内容:cl