PHP 致命 PHP fatal error : __clone method called on non-object

标签 php symfony symfony-2.8

所以,我正在做一个项目,我遇到了一个问题,因为我不断收到错误和警告。我对 PHP 很陌生,所以要温柔。该程序使用 PHP 5.5 运行良好但是当我在 PHP 5.6 中运行该程序时,我收到如下几个错误;

[10-Oct-2016 10:04:46 America/Denver] PHP Warning: Erroneous data format for unserializing 'MMR\Bundle\CodeTyperBundle\Entity\User' in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 833 [10-Oct-2016 10:04:46 America/Denver] PHP Notice: unserialize(): Error at offset 49 of 50 bytes in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 833 [10-Oct-2016 10:04:46 America/Denver] PHP Fatal error: __clone method called on non-object in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 837



项目信息

平台:Symfony
PHP版本:5.6

受影响的代码
public function newInstance()
{
    if ($this->_prototype === null) {
        if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
            $this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
        } else {
           $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); //Line 833
        }
    }

  return clone $this->_prototype; //Line 837
}

任何帮助将不胜感激

最佳答案

我测试过:
var_dump(clone $t=unserialize(sprintf('O:%d:"%s":0:{}', strlen('name'), 'name')));
它有效。

您必须检查 $this->name 的值也许它是空的或有非法字符。
$this->name 在哪里首先设置?

关于PHP 致命 PHP fatal error : __clone method called on non-object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39981499/

相关文章:

php - get_template_part 和 get_footer 的一页 wordpress 问题

php - 我怎样才能只显示小时和分钟?

php - 基本的PHP MySQL数组分组问题

php - 在博客的帖子中上传图像的有效方法?

"collection"表单上的 Symfony2 属性路径解析错误

php - 如何使用 FOSUserBundle 创建 "two"(聊天和管理)或更安全的区域

symfony - usePutenv 默认更改弃用警告修复

php - SQLSTATE[HY000] : General error: 13 Can't get stat of './pics' (Errcode: 13 - Permission denied)

php - 在 Twig 上执行闭包

php - 下载文件时如何修复奇怪的文件编码?