草庐IT

this_call

全部标签

php - $this 在回调函数中

我想知道为什么会这样:classFoo{publicfunctiondoSomethingFunny($subject){preg_replace_callback("#pattern#",array($this,'doX'),$subject);}privatefunctiondoX(){echo'whydoesthiswork?';}}为什么回调还在$this的上下文中?我希望它只允许公共(public)方法。我缺少有关回调工作原理的一些基本知识。 最佳答案 preg_replace_callback()中的回调参数允许调用方法

PHP eBay API GeteBayOfficialTime 调用返回 'Unsupported API call' 错误

我试图从eBay中提取卖家列表,但每次运行此代码时,我都会收到错误TheAPIcall"GeteBayOfficialTime"isinvalidornotsupportedinthisrelease我在装有ZendServer的Mac上运行它。PHP请求:define('XML_POST_URL','https://api.sandbox.ebay.com/ws/api.dll');$theData='MyAuthKey11Low2011-07-12T21:59:59.005Z2011-07-30T21:59:59.005ZReturnAll';$headers=array('Con

php - Zend Layout 中的 $this 变量

我正在阅读一些关于zend框架的教程和文档,在我遇到$this之前,大多数事情都是有意义的/application/layout/scripts/layout.phtml中的变量,有人提到$this是在引导过程中创建的View对象的一个​​实例。据我所知,您不能使用$this作为变量名因为$this是php的保留关键字,用于在类上下文中引用相同的对象。任何将其用作变量的尝试都将导致fatalerror并显示以下错误消息Fatalerror:Cannotre-assign$this并根据作者的陈述Thereisavariable,$this,availablewhichisaninsta

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 - call_user_method_array 函数已弃用,用什么代替它?

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

php - 如何从评估范围中删除 $this?

我正在编写简单的模板引擎和堆栈问题:$this即使在取消设置后仍落入eval范围。classfoo{publicfunctionmethod(){$code='var_dump(isset($this));';unset($this);var_dump(isset($this));//produce:booleanfalseeval($code);//produce:booleantrue}}$foo=newfoo;$foo->method();如何在不修改$code值的情况下避免这种情况? 最佳答案 我建议创建unboundclo

php - ftp_connect fatal error : call undefined function

出于某种原因,ftp_connect()函数不起作用,当我尝试使用它时,它以fatalerror结束,指出此函数未定义...令人惊讶的是我仍然可以使用ftp客户端或使用ftp连接通过终端。我该如何解决这个问题?我在MountainLion上运行,我有5.3php版本-我重新安装了一次,希望这能解决我的问题。 最佳答案 检查PHPFTPinstallationmanual在PHP7上,您可以通过将此行添加到php.ini文件来启用它。extension=php_ftp.dll在PHP8+上启用php.ini中的这一行:extensio

php - fatal error : Call to a member function check_capabilities() on a non-object

我在functions.php中编写了这段代码,以向我的主题个性化添加一个部分。但是当我想打开“localhost/wordpress/wp-admin/customize.php?theme=eye-theme”来查看我的结果时,我看到了这个错误:Fatalerror:Calltoamemberfunctioncheck_capabilities()onanon-objectinC:\xampp\htdocs\xampp\wordpress\wp-includes\class-wp-customize-control.phponline233这是我的functions.php:add

php - 在 php 类方法中使用 $this 就像 return

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:PHPmethodchainingbenefits?PHPOOP:MethodChaining谁能告诉我为什么要使用返回$这个;在php类方法中,我在一些方法类中看到了这一点,例如:publicfunctionregisterPrefix($prefix,$path){if(isset($this->prefixes[$prefix])){$path=array_merge($this->prefixes[$prefix],(array)$path);}$this->prefixes[$prefix]=(ar

php - 使用 $this->referer() 的 cakePHP 重定向无法正常工作

我有一个TestController的View文件并且在上面我添加了评论表单(我的页面所在的页面的url是www.example.com/test/view/slug)现在评论表单发布在urlwww.example.com/comments/addAction评论添加成功后我已经写了(在评论/添加方法)$this->redirect($this->referer());我期待的是它应该重定向到www.example.com/test/view/slug。它在我本地主机上的那个url上重定向,但是当我部署我的应用程序时,它是重定向而不是重定向属性,它是在urlwww.example.co