草庐IT

context_dict

全部标签

php - fatal error : Using $this when not in object context - OOPHP

我只是想通过构造函数设置post_id并通过另一个函数获取该id。但它正在返回:fatalerror:不在对象上下文中时使用$this但不知道为什么会这样正在发生。我以前做过很多次,但现在出了问题。代码如下classPostData{privatestatic$instance=null;public$post_id=0;publicfunction__construct($post_id=0){if((int)$post_id>0){$this->setId($post_id);}}privatefunctionsetId($post_id){return$this->post_id

arrays - "Can' t use function return value in write context”PHP错误

Fatalerror:Can'tusefunctionreturnvalueinwritecontextinline3,在什么情况下会触发此类错误?我的程序://QUERYVARIABLE$query="select*formuserwhereuser_name='$user_name'anduser_password='sha($user_password)'";//ESTABLISHINGCONNECTION$result=mysqli_query($dbc,$query)ordie('ErrorQueryingDatabase');while($row=mysqli_num_ro

php - fatal error : Using $this when not in object context

我收到此fatalerror消息:不在对象上下文中时使用$this。此类在CodeIgniter中设置为一个库。这是我的课:classMy_class{function__construct(){$this->app=base_url('application').'/cache/';if($this->expire_after==''){$this->expire_after=300;}}staticfunctionstore($key,$value){$key=sha1($key);$value=serialize($value);file_put_contents($this->

PHP 类 - fatal error : Can't use method return value in write context

mysqli=newmysqli($this->dbHost,$this->dbLogin,$this->dbPwd,$this->dbName);if(mysqli_connect_errno()){echo"ConnectionFailed:".mysqli_connect_errno();exit();}}publicfunctionaddress(){if($stmt=$this->mysqli->prepare("SELECT`email_content`FROM`content`WHERE`content_name`=?")){$content='address';$stm

php - stream_context_set_params 与 stream_context_set_option

文档怎么说通过阅读php.net,在我看来,stream_context_set_params几乎与stream_context_set_option做同样的事情。即。http://www.php.net/manual/en/function.stream-context-set-params.phpboolstream_context_set_params(resource$stream_or_context,array$params)http://www.php.net/manual/en/function.stream-context-set-option.phpboolstre

php - Magento 2:传递给 Controller::__construct() 的参数 1 必须是 ..\..\..\Action\Context 的实例,给定的 ..\..\..\ObjectManager 的实例

当我尝试运行我的Magento2模块时出现以下错误:Fatalerror:UncaughtTypeError:Argument1passedtoMyModule\Service\Controller\Module\Version::__construct()mustbeaninstanceofMagento\Framework\App\Action\Context,instanceofMagento\Framework\ObjectManager\ObjectManagergiven,calledin/srv/www/vendor/magento/framework/ObjectMan

php - 身份验证凭证未找到异常 : The security context contains no authentication token

我收到以下错误AuthenticationCredentialsNotFoundException:Thesecuritycontextcontainsnoauthenticationtoken.OnepossiblereasonmaybethatthereisnofirewallconfiguredforthisURL.我已经尝试过解决方案,因为我知道当没有为路由配置安全防火墙时会发生此错误,但我似乎无法解决该错误。这是我的security.ymlsecurity:access_decision_manager:#strategycanbe:affirmative,unanimous

php - 错误 : Using $this when not in object context

这个问题在这里已经有了答案:PHPFatalerror:Using$thiswhennotinobjectcontext(9个回答)关闭9年前。我已经查找了涵盖此错误的其他问题,但找不到适用于我的问题的案例。基本上,我的类中的静态方法调用一个非静态方法,该方法反过来调用另一个非静态方法。这会引发fatalerror:Fatalerror:Using$thiswhennotinobjectcontextinclass.phponline...我不明白为什么不能通过$this从另一个非静态类方法调用一个非静态类方法。是因为它们都是从静态函数调用的,因此没有$this实例吗?这是(简化的)类

php - 我可以使用其中一个场景作为我的元步骤而不是在 Context 类中定义它吗?

我需要定义元步骤,例如我的订单中有一件商品。但是我不想在Context类中为这个步骤创建定义,而是只想使用某些功能文件中的现有步骤。因为我已经有了测试功能Addingitemtoordercart的场景。有现成的解决方案吗?我认为这是非常流行的用例,并且必须有比在Context类中定义元步骤更好的解决方案。 最佳答案 简短回答:否。我知道它可能看起来像一个非常有用的功能,但它会很快咬住你,导致步骤/场景之间不必要的依赖性,从而导致脆弱的测试。解决方案是将您的上下文文件视为功能文件和PHP代码之间的桥梁。这意味着上下文文件方法很短,并

相当于 Python dict.get() 的 PHP 关联数组

我已经离开PHP世界几年了,最近接手了一个PHP项目。一些在PHP中应该相当容易的事情却让我望而却步。在Python中,我可以执行以下操作:value=some_dict.get(unknown_key,default_value)我在PHP中做同样的事情的第一个猜测是:$value=$some_array[$unknown_key]||$default_value;但是$value变成了bool值,因为PHP不支持值短路。我还收到一个Notice:Undefinedindex:the_key但我知道我可以通过前缀@来抑制它。有没有办法在PHP中实现与Python的dict.get(k