草庐IT

enabled_shared_from_this

全部标签

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 - 如何从评估范围中删除 $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 - REST 风格的 PHP : how does it work from client side to server side?

我对RESTfulPHP上的教程/示例感到困惑。他们中的大多数都在使用框架(例如Slim)并且最终成为API,这让我更加困惑。在彻底理解如何创建一个简单的RESTfulPHP之前,我想从一开始就避免所有框架和APIMaterial。我明白了,REST,atit'score,isreallyjustaboutusingtherightHTTPverbforthejob.GET,POST,PUT,DELETEallhavemeanings,andifsomethingisdescribedasbeingRESTful,allitreallymeansisthatthesite/appinq

PHP 7.1 : Get file path from namespace

我有一个项目。我需要获取包中文件的内容。我可以用艰难的方式做到这一点:file_get_contents('../../vendor/{vendor}/{package}/src/{directory}/{sub-directory}/class.php');或者,我可以用“简单的方法”做到这一点,我敢肯定这是不可能的。namespaceMyVendor\MyProject;useTheirVendor\TheirPackage\TheirClass;classMyObject{publicfunctionmyFunction(){returnfile_get_contents(The

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 - SELECT * FROM Table WHERE Column LIKE %?%

基于这里的信息MySQLqueryStringcontains尝试使用?创建pdo查询实验如下SELECT*FROMTableWHEREColumnLIKE%?%SELECT*FROMTableWHEREColumnLIKE?%SELECT*FROMTableWHEREColumnLIKE%?没有任何作用。获取错误Syntaxerrororaccessviolation:1064YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtouse

PHP 优化 : Fetching from database

我有一些PHP代码,一旦按下下一个箭头,它基本上只会获取数据库中的下一张图像。然而,在我的网站上,我有时可以有600多个在线用户都点击下一步。有什么方法可以优化此php代码以更快地执行?谢谢!$nxtImage=mysql_query("SELECT*FROMimagesWHEREactive=1andid>$idandsection=$sectionORDERBYidASCLIMIT1")ordie(mysql_error());$nxtrow=mysql_fetch_array($nxtImage);$nxtnum=mysql_num_rows($nxtImage);$nid=$n

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

php - 为什么 PHP 需要显式引用 "$this"才能调用成员函数?

差不多就这些了。大多数OO编程语言中的作用域可以很好地解析符号,而无需显式引用当前实例(即PHP中的“$this”)。为什么PHP要求我在每次调用同一类中的成员函数之前使用$this? 最佳答案 解析函数调用的范围。考虑:$this->strstr(...只是strstr(...后者将调用PHP内置的strstr()函数,这不是我们在这里要做的。这是将OOP功能添加到高级过程/脚本语言的结果。 关于php-为什么PHP需要显式引用"$this"才能调用成员函数?,我们在StackOver

php - date_parse_from_format 到 unix 时间戳

我对date_parse_from_format()方法有疑问:$parsed=date_parse_from_format("YdMH:iT",'201228Nov21:00CET');Returnsassociativearraywithdetailedinfoaboutgivendate.这将返回一个包含一些日期信息的数组。但是有什么方法可以将它转换为unix时间戳吗? 最佳答案 约翰,下面是如何在您的场景中实现mktime的具体示例:$parsed=date_parse_from_format("YdMH:iT",'2012