You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #61424 [HttpKernel][Mime][Serializer][String][Validator] Replace __sleep/wakeup() by __(un)serialize() (nicolas-grekas)
This PR was merged into the 8.0 branch.
Discussion
----------
[HttpKernel][Mime][Serializer][String][Validator] Replace `__sleep/wakeup()` by `__(un)serialize()`
| Q | A
| ------------- | ---
| Branch? | 8.0
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | Fix#61407
| License | MIT
This gets rid of all usages of `__sleep/wakeup()` while preserving FC/BC for payloads.
Commits
-------
2b841c1 [HttpKernel][Mime][Serializer][String][Validator] Replace `__sleep/wakeup()` by `__(un)serialize()`
Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
+2-61Lines changed: 2 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -86,71 +86,12 @@ protected function getCasters(): array
86
86
87
87
publicfunction__serialize(): array
88
88
{
89
-
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
90
-
return ['data' => $this->data];
91
-
}
92
-
93
-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
94
-
95
-
$data = [];
96
-
foreach ($this->__sleep() as$key) {
97
-
try {
98
-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
99
-
$data[$key] = $r->getValue($this);
100
-
}
101
-
} catch (\ReflectionException) {
102
-
$data[$key] = $this->$key;
103
-
}
104
-
}
105
-
106
-
return$data;
89
+
return ['data' => $this->data];
107
90
}
108
91
109
92
publicfunction__unserialize(array$data): void
110
93
{
111
-
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
112
-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
113
-
}
114
-
115
-
if (\in_array(array_keys($data), [['data'], ["\0*\0data"]], true)) {
trigger_deprecation('symfony/http-kernel', '7.4', 'Passing more than just key "data" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Kernel.php
+11-82Lines changed: 11 additions & 82 deletions
Original file line number
Diff line number
Diff line change
@@ -751,95 +751,24 @@ private function preBoot(): ContainerInterface
751
751
752
752
publicfunction__serialize(): array
753
753
{
754
-
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
755
-
return [
756
-
'environment' => $this->environment,
757
-
'debug' => $this->debug,
758
-
];
759
-
}
760
-
761
-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
762
-
763
-
$data = [];
764
-
foreach ($this->__sleep() as$key) {
765
-
try {
766
-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
767
-
$data[$key] = $r->getValue($this);
768
-
}
769
-
} catch (\ReflectionException) {
770
-
$data[$key] = $this->$key;
771
-
}
772
-
}
773
-
774
-
return$data;
754
+
return [
755
+
'environment' => $this->environment,
756
+
'debug' => $this->debug,
757
+
];
775
758
}
776
759
777
760
publicfunction__unserialize(array$data): void
778
761
{
779
-
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
780
-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
781
-
}
782
-
783
-
if (\in_array(array_keys($data), [['environment', 'debug'], ["\0*\0environment", "\0*\0debug"]], true)) {
trigger_deprecation('symfony/http-kernel', '7.4', 'Passing more than just key "environment" and "debug" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Part/AbstractPart.php
+2-43Lines changed: 2 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -65,52 +65,11 @@ abstract public function getMediaSubtype(): string;
65
65
66
66
publicfunction__serialize(): array
67
67
{
68
-
if (!method_exists($this, '__sleep')) {
69
-
return ['headers' => $this->headers];
70
-
}
71
-
72
-
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
73
-
74
-
$data = [];
75
-
foreach ($this->__sleep() as$key) {
76
-
try {
77
-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
78
-
$data[$key] = $r->getValue($this);
79
-
}
80
-
} catch (\ReflectionException) {
81
-
$data[$key] = $this->$key;
82
-
}
83
-
}
84
-
85
-
return$data;
68
+
return ['headers' => $this->headers];
86
69
}
87
70
88
71
publicfunction__unserialize(array$data): void
89
72
{
90
-
if ($wakeup = method_exists($this, '__wakeup') && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
91
-
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
92
-
}
93
-
94
-
if (['headers'] === array_keys($data)) {
95
-
$this->headers = $data['headers'];
96
-
97
-
if ($wakeup) {
98
-
$this->__wakeup();
99
-
}
100
-
101
-
return;
102
-
}
103
-
104
-
trigger_deprecation('symfony/mime', '7.4', 'Passing more than just key "headers" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
0 commit comments