Skip to content

Commit

Permalink
Merge pull request doctrine#1154 from Ocramius/hotfix/PHP-5.6-seriali…
Browse files Browse the repository at this point in the history
…zation-fix

DDC-3120 - PHP 5.6 internal classes/Serializable serialization fix
  • Loading branch information
deeky666 committed Oct 6, 2014
2 parents 072e1ee + 64061ba commit d46fa4a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 5.3
- 5.4
- 5.5
- 5.6

env:
- DB=mysql
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ public function __sleep()
public function newInstance()
{
if ($this->_prototype === null) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513 || PHP_VERSION_ID >= 50600) {
$this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
Expand Down
29 changes: 29 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,31 @@ public function testIsIdentifierMappedSuperClass()

$this->assertFalse($class->isIdentifier('foo'));
}

/**
* @group DDC-3120
*/
public function testCanInstantiateInternalPhpClassSubclass()
{
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');

$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);

$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
}

/**
* @group DDC-3120
*/
public function testCanInstantiateInternalPhpClassSubclassFromUnserializedMetadata()
{
/* @var $classMetadata ClassMetadata */
$classMetadata = unserialize(serialize(new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity')));

$classMetadata->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);

$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
}
}

/**
Expand Down Expand Up @@ -1137,3 +1162,7 @@ public function propertyToColumnName($propertyName, $className = null)
return strtolower($this->classToTableName($className)) . '_' . $propertyName;
}
}

class MyArrayObjectEntity extends \ArrayObject
{
}

0 comments on commit d46fa4a

Please sign in to comment.