Skip to content

Commit 92a6bd1

Browse files
bug symfony#61727 Replace __sleep/wakeup() by __(un)serialize() for throwing and internal usages (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- Replace __sleep/wakeup() by __(un)serialize() for throwing and internal usages | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT This PR replaces `__sleep`/`wakeup()` by `__(un)serialize()`, for throwing and internal usages. This follows the merge of php/php-src#19435 While this change on 8.5 might be reverted (see https://wiki.php.net/rfc/soft-deprecate-sleep-wakeup), we can still remove all those cases. This DOES NOT replace all use cases of `__sleep`/`wakeup()`. We did so already on branch 7.4, but doing it on branch 6.4 is another story. This would basically be way to risky IMHO, with a bunch of non-trivial code to add just to fix the deprecation. My recommendation for those remaining use cases is to ignore the deprecation. By the time ppl will move to PHP 8.5, they will also move away from Symfony 6.4 I'll submit another PR to the phpunit-bridge for that. For the record, here is the list of files/classes that cannot be "just" migrated to `__(un)serialize()` (I'll let the reader wonder about how they could be - and compare their ideas to what we did in 7.4): - src/Symfony/Component/HttpKernel/Profiler/Profile.php - src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php - src/Symfony/Component/HttpKernel/Kernel.php - src/Symfony/Component/String/AbstractString.php - src/Symfony/Component/String/LazyString.php - src/Symfony/Component/Mime/Part/SMimePart.php - src/Symfony/Component/Mime/Part/TextPart.php - src/Symfony/Component/Mime/Part/DataPart.php - src/Symfony/Component/Validator/Constraint.php - src/Symfony/Component/Validator/Mapping/GenericMetadata.php - src/Symfony/Component/Validator/Mapping/MemberMetadata.php - src/Symfony/Component/Validator/Mapping/ClassMetadata.php - src/Symfony/Component/Serializer/Mapping/AttributeMetadata.php - src/Symfony/Component/Serializer/Mapping/ClassMetadata.php Commits ------- ef4e3d6 Replace __sleep/wakeup() by __(un)serialize() for throwing and internal usages
2 parents 9eab435 + ef4e3d6 commit 92a6bd1

File tree

54 files changed

+344
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+344
-480
lines changed

.github/expected-missing-return-types.diff

Lines changed: 14 additions & 169 deletions
Large diffs are not rendered by default.

src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,12 @@ private function sendToElasticsearch(array $records): void
149149
$this->wait(false);
150150
}
151151

152-
public function __sleep(): array
152+
public function __serialize(): array
153153
{
154154
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
155155
}
156156

157-
/**
158-
* @return void
159-
*/
160-
public function __wakeup()
157+
public function __unserialize(array $data): void
161158
{
162159
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
163160
}

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ public function __construct(array $mockedNamespaces = [])
9393
}
9494
}
9595

96-
public function __sleep()
96+
public function __serialize(): array
9797
{
9898
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
9999
}
100100

101-
public function __wakeup()
101+
public function __unserialize(array $data): void
102102
{
103103
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
104104
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ protected function build(ContainerBuilder $container): void
8989
$container->registerExtension(new TestDumpExtension());
9090
}
9191

92-
public function __sleep(): array
92+
public function __serialize(): array
9393
{
94-
return ['varDir', 'testCase', 'rootConfig', 'environment', 'debug'];
94+
return [$this->varDir, $this->testCase, $this->rootConfig, $this->environment, $this->debug];
9595
}
9696

97-
public function __wakeup(): void
97+
public function __unserialize(array $data): void
9898
{
99-
foreach ($this as $k => $v) {
99+
[$this->varDir, $this->testCase, $this->rootConfig, $this->environment, $this->debug] = $data;
100+
101+
foreach ($this as $v) {
100102
if (\is_object($v)) {
101103
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
102104
}

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public function getLogDir(): string
6363
return $this->cacheDir;
6464
}
6565

66-
public function __sleep(): array
66+
public function __serialize(): array
6767
{
6868
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
6969
}
7070

71-
public function __wakeup(): void
71+
public function __unserialize(array $data): void
7272
{
7373
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
7474
}

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/flex-style/src/FlexStyleMicroKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public function getProjectDir(): string
6464
return \dirname((new \ReflectionObject($this))->getFileName(), 2);
6565
}
6666

67-
public function __sleep(): array
67+
public function __serialize(): array
6868
{
6969
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
7070
}
7171

72-
public function __wakeup(): void
72+
public function __unserialize(array $data): void
7373
{
7474
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
7575
}

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,12 @@ public function reset()
294294
$this->tags instanceof ResettableInterface && $this->tags->reset();
295295
}
296296

297-
public function __sleep(): array
297+
public function __serialize(): array
298298
{
299299
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
300300
}
301301

302-
/**
303-
* @return void
304-
*/
305-
public function __wakeup()
302+
public function __unserialize(array $data): void
306303
{
307304
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
308305
}

src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function testErrorsDontInvalidate()
373373

374374
class NotUnserializable
375375
{
376-
public function __wakeup()
376+
public function __unserialize(array $data): void
377377
{
378378
throw new \Exception(__CLASS__);
379379
}

src/Symfony/Component/Cache/Tests/Psr16CacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected function isPruned(CacheInterface $cache, string $name): bool
176176

177177
class NotUnserializable
178178
{
179-
public function __wakeup()
179+
public function __unserialize(array $data): void
180180
{
181181
throw new \Exception(__CLASS__);
182182
}

src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,12 @@ public function reset(): void
276276
$this->ids = [];
277277
}
278278

279-
public function __sleep(): array
279+
public function __serialize(): array
280280
{
281281
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
282282
}
283283

284-
/**
285-
* @return void
286-
*/
287-
public function __wakeup()
284+
public function __unserialize(array $data): void
288285
{
289286
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
290287
}

0 commit comments

Comments
 (0)