Skip to content

Commit d4150be

Browse files
bug #45532 Fix deprecations on PHP 8.2 (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- Fix deprecations on PHP 8.2 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | On the road to #44282 | License | MIT | Doc PR | - Commits ------- ca56620 Fix deprecations on PHP 8.2
2 parents 09ec24d + ca56620 commit d4150be

File tree

23 files changed

+204
-77
lines changed

23 files changed

+204
-77
lines changed

.github/workflows/unit-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- php: '8.1'
3131
mode: low-deps
3232
- php: '8.2'
33-
mode: experimental
33+
#mode: experimental
3434
fail-fast: false
3535

3636
runs-on: ubuntu-20.04

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
use Doctrine\Common\Collections\ArrayCollection;
1515
use Doctrine\DBAL\Types\Type;
16+
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1617
use Doctrine\ORM\Tools\SchemaTool;
1718
use Doctrine\Persistence\ManagerRegistry;
18-
use Doctrine\Persistence\Mapping\ClassMetadata;
1919
use Doctrine\Persistence\ObjectManager;
2020
use Doctrine\Persistence\ObjectRepository;
2121
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
@@ -111,7 +111,7 @@ protected function createEntityManagerMock($repositoryMock)
111111
->willReturn($repositoryMock)
112112
;
113113

114-
$classMetadata = $this->createMock(ClassMetadata::class);
114+
$classMetadata = $this->createMock(ClassMetadataInfo::class);
115115
$classMetadata
116116
->expects($this->any())
117117
->method('hasField')

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ function ($definition) {
194194
}
195195
}
196196

197+
#[\AllowDynamicProperties]
197198
final class DummyClass implements DummyInterface, SunnyInterface
198199
{
199200
private $ref;

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1415
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617

@@ -28,14 +29,18 @@ public function process(ContainerBuilder $container)
2829
// "annotation_reader" at build time don't get any cache
2930
foreach ($container->findTaggedServiceIds('annotations.cached_reader') as $id => $tags) {
3031
$reader = $container->getDefinition($id);
32+
$reader->setPublic(false);
3133
$properties = $reader->getProperties();
3234

3335
if (isset($properties['cacheProviderBackup'])) {
3436
$provider = $properties['cacheProviderBackup']->getValues()[0];
3537
unset($properties['cacheProviderBackup']);
3638
$reader->setProperties($properties);
37-
$container->set($id, null);
38-
$container->setDefinition($id, $reader->replaceArgument(1, $provider));
39+
$reader->replaceArgument(1, $provider);
40+
} elseif (4 <= \count($arguments = $reader->getArguments()) && $arguments[3] instanceof ServiceClosureArgument) {
41+
$arguments[1] = $arguments[3]->getValues()[0];
42+
unset($arguments[3]);
43+
$reader->setArguments($arguments);
3944
}
4045
}
4146
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1463,9 +1463,10 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14631463

14641464
$container
14651465
->getDefinition('annotations.cached_reader')
1466+
->setPublic(true) // set to false in AddAnnotationsCachedReaderPass
14661467
->replaceArgument(2, $config['debug'])
1467-
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
1468-
->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
1468+
// reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
1469+
->addArgument(new ServiceClosureArgument(new Reference($cacheService)))
14691470
->addTag('annotations.cached_reader')
14701471
;
14711472

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static function configureStatic1()
5656

5757
class BarUserClass
5858
{
59+
public $foo;
5960
public $bar;
6061

6162
public function __construct(BarClass $bar)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/foo.php

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class FooClass
66
{
7+
public $qux;
78
public $foo;
89
public $moo;
910

src/Symfony/Component/DomCrawler/Crawler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,11 @@ private function convertToHtmlEntities(string $htmlContent, string $charset = 'U
12141214
set_error_handler(function () { throw new \Exception(); });
12151215

12161216
try {
1217-
return mb_convert_encoding($htmlContent, 'HTML-ENTITIES', $charset);
1217+
return mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], $charset);
12181218
} catch (\Exception|\ValueError $e) {
12191219
try {
12201220
$htmlContent = iconv($charset, 'UTF-8', $htmlContent);
1221-
$htmlContent = mb_convert_encoding($htmlContent, 'HTML-ENTITIES', 'UTF-8');
1221+
$htmlContent = mb_encode_numericentity($htmlContent, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8');
12221222
} catch (\Exception|\ValueError $e) {
12231223
}
12241224

src/Symfony/Component/Filesystem/Tests/Fixtures/MockStream/MockStream.php

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
class MockStream
1919
{
20+
public $context;
21+
2022
/**
2123
* Opens file or URL.
2224
*

src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectDummy.php

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Symfony\Component\Serializer\Tests\Normalizer\Features;
44

5+
#[\AllowDynamicProperties]
56
class ObjectDummy
67
{
78
protected $foo;

src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ImageValidatorTest extends ConstraintValidatorTestCase
3333
protected $imageLandscape;
3434
protected $imagePortrait;
3535
protected $image4By3;
36+
protected $image16By9;
3637
protected $imageCorrupted;
3738
protected $notAnImage;
3839

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ protected function dumpLine($depth, $endOfValue = false)
978978
}
979979
$this->lastDepth = $depth;
980980

981-
$this->line = mb_convert_encoding($this->line, 'HTML-ENTITIES', 'UTF-8');
981+
$this->line = mb_encode_numericentity($this->line, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8');
982982

983983
if (-1 === $depth) {
984984
AbstractDumper::dumpLine(0);

src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function testHtmlDump()
175175
<span class=sf-dump-meta>trace</span>: {<samp>
176176
<span class=sf-dump-meta title="%sExceptionCasterTest.php
177177
Stack level %d."><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%e</span>Tests%eCaster%eExceptionCasterTest.php</span>:<span class=sf-dump-num>%d</span>
178-
&hellip;%d
178+
&#8230;%d
179179
</samp>}
180180
</samp>}
181181
</bar>

src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ public function testCastObjectStorageDumpsInfo()
166166

167167
public function testCastArrayObject()
168168
{
169-
$var = new \ArrayObject([123]);
169+
$var = new
170+
#[\AllowDynamicProperties]
171+
class([123]) extends \ArrayObject {};
170172
$var->foo = 234;
171173

172174
$expected = <<<EOTXT
173-
ArrayObject {
175+
ArrayObject@anonymous {
174176
+"foo": 234
175177
-storage: array:1 [
176178
0 => 123

src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testGet()
6666
<span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span>
6767
"<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="5 characters">d&%s;j&%s;<span class="sf-dump-default sf-dump-ns">\\n</span></span>"
6868
<span class=sf-dump-key>7</span> => b"""
69-
<span class=sf-dump-str title="11 binary or non-UTF-8 characters">&eacute;<span class="sf-dump-default">\\x00</span>test<span class="sf-dump-default">\\t</span><span class="sf-dump-default sf-dump-ns">\\n</span></span>
69+
<span class=sf-dump-str title="11 binary or non-UTF-8 characters">&#233;<span class="sf-dump-default">\\x00</span>test<span class="sf-dump-default">\\t</span><span class="sf-dump-default sf-dump-ns">\\n</span></span>
7070
<span class=sf-dump-str title="11 binary or non-UTF-8 characters">ing</span>
7171
"""
7272
"<span class=sf-dump-key>[]</span>" => []

src/Symfony/Component/VarDumper/Tests/Fixtures/dumb-var.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Component\VarDumper\Tests\Fixture;
44

55
if (!class_exists(\Symfony\Component\VarDumper\Tests\Fixture\DumbFoo::class)) {
6+
#[\AllowDynamicProperties]
67
class DumbFoo
78
{
89
public $foo = 'foo';

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,15 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
108108
}
109109
$properties = ['SplObjectStorage' => ["\0" => $properties]];
110110
$arrayValue = (array) $value;
111-
} elseif ($value instanceof \Serializable || $value instanceof \__PHP_Incomplete_Class) {
111+
} elseif ($value instanceof \Serializable
112+
|| $value instanceof \__PHP_Incomplete_Class
113+
|| $value instanceof \DatePeriod
114+
|| (\PHP_VERSION_ID >= 80200 && (
115+
$value instanceof \DateTimeInterface
116+
|| $value instanceof \DateTimeZone
117+
|| $value instanceof \DateInterval
118+
))
119+
) {
112120
++$objectsCount;
113121
$objectsPool[$value] = [$id = \count($objectsPool), serialize($value), [], 0];
114122
$value = new Reference($id);

src/Symfony/Component/VarExporter/Internal/Hydrator.php

+36-35
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,14 @@ public static function hydrate($objects, $values, $properties, $value, $wakeups)
5555

5656
public static function getHydrator($class)
5757
{
58-
if ('stdClass' === $class) {
59-
return self::$hydrators[$class] = static function ($properties, $objects) {
60-
foreach ($properties as $name => $values) {
61-
foreach ($values as $i => $v) {
62-
$objects[$i]->$name = $v;
63-
}
64-
}
65-
};
66-
}
67-
68-
if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) {
69-
throw new ClassNotFoundException($class);
70-
}
71-
$classReflector = new \ReflectionClass($class);
72-
73-
if (!$classReflector->isInternal()) {
74-
return self::$hydrators[$class] = (self::$hydrators['stdClass'] ?? self::getHydrator('stdClass'))->bindTo(null, $class);
75-
}
76-
77-
if ($classReflector->name !== $class) {
78-
return self::$hydrators[$classReflector->name] ?? self::getHydrator($classReflector->name);
79-
}
80-
8158
switch ($class) {
82-
case 'ArrayIterator':
83-
case 'ArrayObject':
84-
$constructor = \Closure::fromCallable([$classReflector->getConstructor(), 'invokeArgs']);
85-
86-
return self::$hydrators[$class] = static function ($properties, $objects) use ($constructor) {
59+
case 'stdClass':
60+
return self::$hydrators[$class] = static function ($properties, $objects) {
8761
foreach ($properties as $name => $values) {
88-
if ("\0" !== $name) {
89-
foreach ($values as $i => $v) {
90-
$objects[$i]->$name = $v;
91-
}
62+
foreach ($values as $i => $v) {
63+
$objects[$i]->$name = $v;
9264
}
9365
}
94-
foreach ($properties["\0"] ?? [] as $i => $v) {
95-
$constructor($objects[$i], $v);
96-
}
9766
};
9867

9968
case 'ErrorException':
@@ -122,6 +91,38 @@ public static function getHydrator($class)
12291
};
12392
}
12493

94+
if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) {
95+
throw new ClassNotFoundException($class);
96+
}
97+
$classReflector = new \ReflectionClass($class);
98+
99+
switch ($class) {
100+
case 'ArrayIterator':
101+
case 'ArrayObject':
102+
$constructor = \Closure::fromCallable([$classReflector->getConstructor(), 'invokeArgs']);
103+
104+
return self::$hydrators[$class] = static function ($properties, $objects) use ($constructor) {
105+
foreach ($properties as $name => $values) {
106+
if ("\0" !== $name) {
107+
foreach ($values as $i => $v) {
108+
$objects[$i]->$name = $v;
109+
}
110+
}
111+
}
112+
foreach ($properties["\0"] ?? [] as $i => $v) {
113+
$constructor($objects[$i], $v);
114+
}
115+
};
116+
}
117+
118+
if (!$classReflector->isInternal()) {
119+
return self::$hydrators[$class] = (self::$hydrators['stdClass'] ?? self::getHydrator('stdClass'))->bindTo(null, $class);
120+
}
121+
122+
if ($classReflector->name !== $class) {
123+
return self::$hydrators[$classReflector->name] ?? self::getHydrator($classReflector->name);
124+
}
125+
125126
$propertySetters = [];
126127
foreach ($classReflector->getProperties() as $propertyReflector) {
127128
if (!$propertyReflector->isStatic()) {

src/Symfony/Component/VarExporter/Tests/Fixtures/array-object.php

+2-2
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)['ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayObject')),
6-
clone $p['ArrayObject'],
5+
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\ArrayObject')),
6+
clone ($p['ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayObject')),
77
],
88
null,
99
[],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([
5+
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['DateTime'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateTime')),
6+
clone ($p['DateTimeImmutable'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateTimeImmutable')),
7+
clone ($p['DateTimeZone'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateTimeZone')),
8+
clone ($p['DateInterval'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateInterval')),
9+
], [
10+
4 => 'O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2012-07-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:7;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}s:11:"recurrences";i:5;s:18:"include_start_date";b:1;}',
11+
]),
12+
null,
13+
[
14+
'stdClass' => [
15+
'date' => [
16+
'1970-01-01 00:00:00.000000',
17+
'1970-01-01 00:00:00.000000',
18+
],
19+
'timezone_type' => [
20+
1,
21+
1,
22+
3,
23+
],
24+
'timezone' => [
25+
'+00:00',
26+
'+00:00',
27+
'Europe/Paris',
28+
],
29+
'y' => [
30+
3 => 0,
31+
],
32+
'm' => [
33+
3 => 0,
34+
],
35+
'd' => [
36+
3 => 7,
37+
],
38+
'h' => [
39+
3 => 0,
40+
],
41+
'i' => [
42+
3 => 0,
43+
],
44+
's' => [
45+
3 => 0,
46+
],
47+
'f' => [
48+
3 => 0.0,
49+
],
50+
'weekday' => [
51+
3 => 0,
52+
],
53+
'weekday_behavior' => [
54+
3 => 0,
55+
],
56+
'first_last_day_of' => [
57+
3 => 0,
58+
],
59+
'invert' => [
60+
3 => 0,
61+
],
62+
'days' => [
63+
3 => false,
64+
],
65+
'special_type' => [
66+
3 => 0,
67+
],
68+
'special_amount' => [
69+
3 => 0,
70+
],
71+
'have_weekday_relative' => [
72+
3 => 0,
73+
],
74+
'have_special_relative' => [
75+
3 => 0,
76+
],
77+
],
78+
],
79+
[
80+
$o[0],
81+
$o[1],
82+
$o[2],
83+
$o[3],
84+
$o[4],
85+
],
86+
[
87+
1 => 0,
88+
1,
89+
2,
90+
3,
91+
]
92+
);

0 commit comments

Comments
 (0)