所以,我正在做一个项目,我遇到了一个问题,因为我不断收到错误和警告。我对 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/