Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d46fa4a

Browse files
committed
Merge pull request #1154 from Ocramius/hotfix/PHP-5.6-serialization-fix
DDC-3120 - PHP 5.6 internal classes/Serializable serialization fix
2 parents 072e1ee + 64061ba commit d46fa4a

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ php:
44
- 5.3
55
- 5.4
66
- 5.5
7+
- 5.6
78

89
env:
910
- DB=mysql

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ public function __sleep()
866866
public function newInstance()
867867
{
868868
if ($this->_prototype === null) {
869-
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
869+
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513 || PHP_VERSION_ID >= 50600) {
870870
$this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
871871
} else {
872872
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));

tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,31 @@ public function testIsIdentifierMappedSuperClass()
11011101

11021102
$this->assertFalse($class->isIdentifier('foo'));
11031103
}
1104+
1105+
/**
1106+
* @group DDC-3120
1107+
*/
1108+
public function testCanInstantiateInternalPhpClassSubclass()
1109+
{
1110+
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
1111+
1112+
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
1113+
1114+
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
1115+
}
1116+
1117+
/**
1118+
* @group DDC-3120
1119+
*/
1120+
public function testCanInstantiateInternalPhpClassSubclassFromUnserializedMetadata()
1121+
{
1122+
/* @var $classMetadata ClassMetadata */
1123+
$classMetadata = unserialize(serialize(new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity')));
1124+
1125+
$classMetadata->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
1126+
1127+
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
1128+
}
11041129
}
11051130

11061131
/**
@@ -1137,3 +1162,7 @@ public function propertyToColumnName($propertyName, $className = null)
11371162
return strtolower($this->classToTableName($className)) . '_' . $propertyName;
11381163
}
11391164
}
1165+
1166+
class MyArrayObjectEntity extends \ArrayObject
1167+
{
1168+
}

0 commit comments

Comments
 (0)