bug #29209 [VarExporter] fix handling of __sleep() (nicolas-grekas)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[VarExporter] fix handling of __sleep()
| Q | A
| ------------- | ---
| Branch? | 4.2
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #29118
| License | MIT
| Doc PR | -
Commits
-------
46e2ecd5c8
[VarExporter] fix handling of __sleep()
This commit is contained in:
commit
100f2056b7
@ -119,11 +119,10 @@ class Exporter
|
||||
$proto = (array) $proto;
|
||||
|
||||
foreach ($arrayValue as $name => $v) {
|
||||
$i = 0;
|
||||
$n = (string) $name;
|
||||
if ('' === $n || "\0" !== $n[0]) {
|
||||
$c = 'stdClass';
|
||||
$properties[$c][$n] = $v;
|
||||
unset($sleep[$n]);
|
||||
} elseif ('*' === $n[1]) {
|
||||
$n = substr($n, 3);
|
||||
$c = $reflector->getProperty($n)->class;
|
||||
@ -132,26 +131,26 @@ class Exporter
|
||||
} elseif ('Exception' === $c) {
|
||||
$c = 'ErrorException';
|
||||
}
|
||||
$properties[$c][$n] = $v;
|
||||
unset($sleep[$n]);
|
||||
} else {
|
||||
$i = strpos($n, "\0", 2);
|
||||
$c = substr($n, 1, $i - 1);
|
||||
$n = substr($n, 1 + $i);
|
||||
if (null === $sleep) {
|
||||
$properties[$c][$n] = $v;
|
||||
} elseif (isset($sleep[$n]) && $c === $class) {
|
||||
$properties[$c][$n] = $v;
|
||||
unset($sleep[$n]);
|
||||
}
|
||||
}
|
||||
if (\array_key_exists($name, $proto) && $proto[$name] === $v) {
|
||||
unset($properties[$c][$n]);
|
||||
if (null !== $sleep) {
|
||||
if (!isset($sleep[$n]) || ($i && $c !== $class)) {
|
||||
continue;
|
||||
}
|
||||
$sleep[$n] = false;
|
||||
}
|
||||
if (!\array_key_exists($name, $proto) || $proto[$name] !== $v) {
|
||||
$properties[$c][$n] = $v;
|
||||
}
|
||||
}
|
||||
if ($sleep) {
|
||||
foreach ($sleep as $n => $v) {
|
||||
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), E_USER_NOTICE);
|
||||
if (false !== $v) {
|
||||
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
|
||||
$o = [
|
||||
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\MyWakeup'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyWakeup')),
|
||||
],
|
||||
null,
|
||||
[],
|
||||
$o[0],
|
||||
[
|
||||
1 => 0,
|
||||
]
|
||||
);
|
@ -12,9 +12,6 @@ return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
|
||||
$o[1],
|
||||
123,
|
||||
],
|
||||
'bis' => [
|
||||
1 => 123,
|
||||
],
|
||||
'baz' => [
|
||||
1 => 123,
|
||||
],
|
||||
|
@ -97,6 +97,9 @@ class VarExporterTest extends TestCase
|
||||
$marshalledValue = include $fixtureFile;
|
||||
|
||||
if (!$isStaticValue) {
|
||||
if ($value instanceof MyWakeup) {
|
||||
$value->bis = null;
|
||||
}
|
||||
$this->assertDumpEquals($value, $marshalledValue);
|
||||
} else {
|
||||
$this->assertSame($value, $marshalledValue);
|
||||
@ -184,6 +187,11 @@ class VarExporterTest extends TestCase
|
||||
yield array('final-array-iterator', new FinalArrayIterator());
|
||||
|
||||
yield array('final-stdclass', new FinalStdClass());
|
||||
|
||||
$value = new MyWakeup();
|
||||
$value->bis = new \ReflectionClass($value);
|
||||
|
||||
yield array('wakeup-refl', $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user