首页 文章

PHP Fatal PHP致命错误:在非对象上调用__clone方法

提问于
浏览
2

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

[10-Oct-2016 10:04:46 America / Denver] PHP警告:在/hermes/bosnaweb14a/b1234/.../application/vendor中反序列化'MMR \ Bundle \ CodeTyperBundle \ Entity \ User'的错误数据格式第833行的/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php [10-Oct-2016 10:04:46 America / Denver] PHP注意:unserialize():错误在偏移49处50字节/第833行的Hermes / bosnaweb14a / b1234 /.../ application / vendor / doctrine / orm / lib / Doctrine / ORM / Mapping / ClassMetadataInfo.php [10-Oct-2016 10:04:46 America / Denver] PHP致命错误:在837行的/hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php中调用非对象的__clone方法

项目信息

平台: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
}

任何帮助将不胜感激

1 回答

  • 0

    我测试过:

    var_dump(clone $t=unserialize(sprintf('O:%d:"%s":0:{}', strlen('name'), 'name')));

    它有效 .

    你必须检查 $this->name 的值可能是空的或有非法字符 .

    $this->name 首先设置在哪里?

相关问题