我正在开发一个项目,但遇到了错误和警告。由于我对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
}
非常感谢您的帮助。
if
之后或作为第二个条件,也要测试is_object($this->_prototype)
。 - JustOnUnderMillionsunserialize
失败了,可能是因为PHP Notice: unserialize():
的问题。 - JustOnUnderMillions$this->name
字符串中存在未转义的字符,因此unserialize()
函数无法将其解码。 - martin