8000 [VarExporter] Fix handling mangled property names returned by __sleep() · symfony/symfony@e439d33 · GitHub
[go: up one dir, main page]

Skip to content

Commit e439d33

Browse files
[VarExporter] Fix handling mangled property names returned by __sleep()
1 parent 4be9706 commit e439d33

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/Symfony/Component/VarExporter/Internal/Exporter.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,19 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
157157
$n = substr($n, 1 + $i);
158158
}
159159
if (null !== $sleep) {
160-
if (!isset($sleep[$n]) || ($i && $c !== $class)) {
160+
if (!isset($sleep[$name]) && (!isset($sleep[$n]) || ($i && $c !== $class))) {
161161
unset($arrayValue[$name]);
162162
continue;
163163
}
164-
$sleep[$n] = false;
164+
unset($sleep[$name], $sleep[$n]);
165165
}
166166
if (!\array_key_exists($name, $proto) || $proto[$name] !== $v || "\x00Error\x00trace" === $name || "\x00Exception\x00trace" === $name) {
167167
$properties[$c][$n] = $v;
168168
}
169169
}
170170
if ($sleep) {
171171
foreach ($sleep as $n => $v) {
172-
if (false !== $v) {
173-
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
174-
}
172+
trigger_error(sprintf('serialize(): "%s" returned as member variable from __sleep() but does not exist', $n), \E_USER_NOTICE);
175173
}
176174
}
177175
if (method_exists($class, '__unserialize')) {

src/Symfony/Component/VarExporter/Tests/Fixtures/var-on-sleep.php

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
],
77
null,
88
[
9+
'Symfony\\Component\\VarExporter\\Tests\\AbstractClass' => [
10+
'foo' => [
11+
'afternoon',
12+
],
13+
'bar' => [
14+
'morning',
15+
],
16+
],
917
'stdClass' => [
1018
'good' => [
1119
'night',

src/Symfony/Component/VarExporter/Tests/VarExporterTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -346,20 +346,22 @@ public function setFlags($flags): void
346346
}
347347
}
348348

349-
class GoodNight
349+
class GoodNight extends AbstractClass
350350
{
351351
public $good;
352352

353353
public function __construct()
354354
{
355355
unset($this->good);
356+
$this->foo = 'afternoon';
357+
$this->setBar('morning');
356358
}
357359

358360
public function __sleep(): array
359361
{
360362
$this->good = 'night';
361363

362-
return ['good'];
364+
return ['good', 'foo', "\0*\0foo", "\0".parent::class."\0bar"];
363365
}
364366
}
365367

src/Symfony/Component/VarExporter/VarExporter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function export($value, bool &$isStaticValue = null, array &$found
8383
ksort($states);
8484

8585
$wakeups = [null];
86-
foreach ($states as $k => $v) {
86+
foreach ($states as $v) {
8787
if (\is_array($v)) {
8888
$wakeups[-$v[0]] = $v[1];
8989
} else {

0 commit comments

Comments
 (0)
0