Skip to content

Commit 0f020b5

Browse files
Merge branch '6.4' into 7.3
* 6.4: Replace __sleep/wakeup() by __(un)serialize() for throwing and internal usages
2 parents d4dfcd2 + 466fcac commit 0f020b5

File tree

12 files changed

+195
-103
lines changed

12 files changed

+195
-103
lines changed

Tests/Fixtures/GoodNight.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class GoodNight
15+
{
16+
public $good;
17+
protected $foo;
18+
private $bar;
19+
20+
public function __construct()
21+
{
22+
unset($this->good);
23+
$this->foo = 'afternoon';
24+
$this->bar = 'morning';
25+
}
26+
27+
public function __sleep(): array
28+
{
29+
$this->good = 'night';
30+
31+
return ['good', 'foo', "\0*\0foo", "\0".__CLASS__."\0bar"];
32+
}
33+
}

Tests/Fixtures/LazyGhost/MagicClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __get($name)
2727
return $this->data[$name] ?? null;
2828
}
2929

30-
public function __set($name, $value)
30+
public function __set($name, $value): void
3131
{
3232
$this->data[$name] = $value;
3333
}
@@ -37,7 +37,7 @@ public function __isset($name): bool
3737
return isset($this->data[$name]);
3838
}
3939

40-
public function __unset($name)
40+
public function __unset($name): void
4141
{
4242
unset($this->data[$name]);
4343
}

Tests/Fixtures/LazyProxy/TestWakeupClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class TestWakeupClass extends TestClass
1515
{
16-
public function __wakeup()
16+
public function __wakeup(): void
1717
{
1818
$this->dep->wokeUp = true;
1919
}

Tests/Fixtures/MyWakeup.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class MyWakeup
15+
{
16+
public $sub;
17+
public $bis;
18+
public $baz;
19+
public $def = 234;
20+
21+
public function __sleep(): array
22+
{
23+
return ['sub', 'baz'];
24+
}
25+
26+
public function __wakeup(): void
27+
{
28+
if (123 === $this->sub) {
29+
$this->bis = 123;
30+
$this->baz = 123;
31+
}
32+
}
33+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class Php74Serializable implements \Serializable
15+
{
16+
public $foo;
17+
18+
public function __serialize(): array
19+
{
20+
return [$this->foo = new \stdClass()];
21+
}
22+
23+
public function __unserialize(array $data): void
24+
{
25+
[$this->foo] = $data;
26+
}
27+
28+
public function __sleep(): array
29+
{
30+
throw new \BadMethodCallException();
31+
}
32+
33+
public function __wakeup(): void
34+
{
35+
throw new \BadMethodCallException();
36+
}
37+
38+
public function serialize(): string
39+
{
40+
throw new \BadMethodCallException();
41+
}
42+
43+
public function unserialize($ser)
44+
{
45+
throw new \BadMethodCallException();
46+
}
47+
}

Tests/Fixtures/php74-serializable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
44
$o = [
5-
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\Php74Serializable'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Php74Serializable')),
5+
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\Fixtures\\Php74Serializable'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Fixtures\\Php74Serializable')),
66
clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
77
],
88
null,

Tests/Fixtures/var-on-sleep.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
44
$o = [
5-
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\GoodNight'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\GoodNight')),
5+
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\Fixtures\\GoodNight'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Fixtures\\GoodNight')),
66
],
77
null,
88
[
@@ -11,7 +11,7 @@
1111
'night',
1212
],
1313
],
14-
'Symfony\\Component\\VarExporter\\Tests\\GoodNight' => [
14+
'Symfony\\Component\\VarExporter\\Tests\\Fixtures\\GoodNight' => [
1515
'foo' => [
1616
'afternoon',
1717
],

Tests/Fixtures/wakeup-refl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
44
$o = [
5-
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\MyWakeup'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyWakeup')),
5+
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\Fixtures\\MyWakeup'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Fixtures\\MyWakeup')),
66
],
77
null,
88
[],

Tests/Fixtures/wakeup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
44
$o = [
5-
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\MyWakeup'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyWakeup')),
6-
clone $p['Symfony\\Component\\VarExporter\\Tests\\MyWakeup'],
5+
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\Fixtures\\MyWakeup'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Fixtures\\MyWakeup')),
6+
clone $p['Symfony\\Component\\VarExporter\\Tests\\Fixtures\\MyWakeup'],
77
],
88
null,
99
[

Tests/LazyProxyTraitTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@
3131
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestWakeupClass;
3232
use Symfony\Component\VarExporter\Tests\Fixtures\SimpleObject;
3333

34+
$errorHandler = set_error_handler(static function (int $errno, string $errstr) use (&$errorHandler) {
35+
if (\E_DEPRECATED === $errno && str_contains($errstr, 'serialize()')) {
36+
// We're testing if the component handles deprecated Serializable and __sleep/wakeup implementations well.
37+
// This kind of implementation triggers a deprecation warning that we explicitly want to ignore here.
38+
return true;
39+
}
40+
41+
return $errorHandler ? $errorHandler(...\func_get_args()) : false;
42+
});
43+
44+
try {
45+
foreach ([
46+
TestWakeupClass::class,
47+
] as $class) {
48+
class_exists($class);
49+
}
50+
} finally {
51+
restore_error_handler();
52+
}
53+
3454
/**
3555
* @requires PHP 8.4
3656
*/

0 commit comments

Comments
 (0)