From 85fea7292cd5c0ba2622ac1cef33850c139748b1 Mon Sep 17 00:00:00 2001 From: joschi127 Date: Mon, 2 Jun 2014 23:24:54 +0200 Subject: [PATCH 1/2] Fix for ClassMetadata::newInstance() PHP 5.5.13 Fixes https://github.com/doctrine/phpcr-odm/issues/498 --- lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php index a88557a08..d332a6067 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php @@ -1464,7 +1464,8 @@ public function __sleep() public function newInstance() { if ($this->prototype === null) { - $this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); + $ref = new ReflectionClass($this->name); + $this->prototype = $ref->newInstanceWithoutConstructor(); } return clone $this->prototype; From 0d3706be616847eed659f4765a06c82058c4bf76 Mon Sep 17 00:00:00 2001 From: joschi127 Date: Mon, 2 Jun 2014 23:40:12 +0200 Subject: [PATCH 2/2] Fix for ClassMetadata::newInstance() PHP 5.5.13 Improved fix for https://github.com/doctrine/phpcr-odm/issues/498 Do it the same way as Doctrine ORM does. The newInstanceWithoutConstructor() is available for PHP 5.4 and higher only, so a check against the used PHP version is required. --- lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php index d332a6067..f369f7765 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php @@ -1464,8 +1464,12 @@ public function __sleep() public function newInstance() { if ($this->prototype === null) { - $ref = new ReflectionClass($this->name); - $this->prototype = $ref->newInstanceWithoutConstructor(); + if (PHP_VERSION_ID >= 50400) { + $rc = new \ReflectionClass($this->name); + $this->prototype = $rc->newInstanceWithoutConstructor(); + } else { + $this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); + } } return clone $this->prototype;