Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5bd676

Browse filesBrowse files
[VarExporter] Fix handling mangled property names returned by __sleep()
1 parent 4be9706 commit c5bd676
Copy full SHA for c5bd676

File tree

Expand file treeCollapse file tree

4 files changed

+17
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+17
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Internal/Exporter.php
+3-5Lines changed: 3 additions & 5 deletions
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Tests/Fixtures/var-on-sleep.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
'night',
1212
],
1313
],
14+
'Symfony\\Component\\VarExporter\\Tests\\GoodNight' => [
15+
'foo' => [
16+
'afternoon',
17+
],
18+
'bar' => [
19+
'morning',
20+
],
21+
],
1422
],
1523
$o[0],
1624
[]

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Tests/VarExporterTest.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,21 @@ public function setFlags($flags): void
349349
class GoodNight
350350
{
351351
public $good;
352+
protected $foo;
353+
private $bar;
352354

353355
public function __construct()
354356
{
355357
unset($this->good);
358+
$this->foo = 'afternoon';
359+
$this->bar = 'morning';
356360
}
357361

358362
public function __sleep(): array
359363
{
360364
$this->good = 'night';
361365

362-
return ['good'];
366+
return ['good', 'foo', "\0*\0foo", "\0".__CLASS__."\0bar"];
363367
}
364368
}
365369

‎src/Symfony/Component/VarExporter/VarExporter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/VarExporter.php
+1-1Lines changed: 1 addition & 1 deletion
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.