8000 bug #30274 [VarDumper] fix serializing Stub instances (nicolas-grekas) · enumag/symfony@ce7afc2 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce7afc2

Browse files
bug symfony#30274 [VarDumper] fix serializing Stub instances (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [VarDumper] fix serializing Stub instances | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - There are more properties in child classes, and we can skip serializing properties that are set to their default values. Commits ------- 46d6a4d [VarDumper] fix serializing Stub instances
2 parents eb32993 + 46d6a4d commit ce7afc2

File tree

1 file changed

+17
-10
lines changed
  • src/Symfony/Component/VarDumper/Cloner

1 file changed

+17
-10
lines changed

src/Symfony/Component/VarDumper/Cloner/Stub.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,29 @@ class Stub
3939
public $position = 0;
4040
public $attr = [];
4141

42+
private static $defaultProperties = [];
43+
4244
/**
4345
* @internal
4446
*/
4547
public function __sleep()
4648
{
47-
$this->serialized = [$this->class, $this->position, $this->cut, $this->type, $this->value, $this->handle, $this->refCount, $this->attr];
49+
$properties = [];
4850

49-
return ['serialized'];
50-
}
51+
if (!isset(self::$defaultProperties[$c = \get_class($this)])) {
52+
self::$defaultProperties[$c] = get_class_vars($c);
5153

52-
/**
53-
* @internal
54-
*/
55-
public function __wakeup()
56-
{
57-
list($this->class, $this->position, $this->cut, $this->type, $this->value, $this->handle, $this->refCount, $this->attr) = $this->serialized;
58-
unset($this->serialized);
54+
foreach ((new \ReflectionClass($c))->getStaticProperties() as $k => $v) {
55+
unset(self::$defaultProperties[$c][$k]);
56+
}
57+
}
58+
59+
foreach (self::$defaultProperties[$c] as $k => $v) {
60+
if ($this->$k !== $v) {
61+
$properties[] = $k;
62+
}
63+
}
64+
65+
return $properties;
5966
}
6067
}

0 commit comments

Comments
 (0)
0