Skip to content

Commit 7eacaa5

Browse files
Merge branch '4.4' into 5.4
* 4.4: Fix composer on appveyor [PropertyAccess] Fix typo in PropertyAccessor::readProperty() DocBlock [VarExporter] Fix exporting objects with readonly properties [ExpressionLanguage] Fix matches when the regexp is not valid [Messenger] Add mysql indexes back and work around deadlocks using soft-delete [Validator] Fix File constraint invalid max size exception message [Console] Fix exit status on uncaught exception with negative code
2 parents 2300360 + ed78ec3 commit 7eacaa5

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

Internal/Exporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
138138
$i = 0;
139139
$n = (string) $name;
140140
if ('' === $n || "\0" !== $n[0]) {
141-
$c = 'stdClass';
141+
$c = \PHP_VERSION_ID >= 80100 && $reflector->hasProperty($n) && ($p = $reflector->getProperty($n))->isReadOnly() ? $p->class : 'stdClass';
142142
} elseif ('*' === $n[1]) {
143143
$n = substr($n, 3);
144144
$c = $reflector->getProperty($n)->class;

Tests/Fixtures/FooReadonly.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 FooReadonly
15+
{
16+
public function __construct(
17+
public readonly string $name,
18+
public readonly string $value,
19+
) {
20+
}
21+
}

Tests/Fixtures/readonly.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
4+
$o = [
5+
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooReadonly'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooReadonly')),
6+
],
7+
null,
8+
[
9+
'Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooReadonly' => [
10+
'name' => [
11+
'k',
12+
],
13+
'value' => [
14+
'v',
15+
],
16+
],
17+
],
18+
$o[0],
19+
[]
20+
);

Tests/VarExporterTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\VarExporter\Exception\ClassNotFoundException;
1717
use Symfony\Component\VarExporter\Exception\NotInstantiableTypeException;
1818
use Symfony\Component\VarExporter\Internal\Registry;
19+
use Symfony\Component\VarExporter\Tests\Fixtures\FooReadonly;
1920
use Symfony\Component\VarExporter\Tests\Fixtures\FooSerializable;
2021
use Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum;
2122
use Symfony\Component\VarExporter\Tests\Fixtures\MySerializable;
@@ -244,9 +245,12 @@ public function provideExport()
244245

245246
yield ['php74-serializable', new Php74Serializable()];
246247

247-
if (\PHP_VERSION_ID >= 80100) {
248-
yield ['unit-enum', [FooUnitEnum::Bar], true];
248+
if (\PHP_VERSION_ID < 80100) {
249+
return;
249250
}
251+
252+
yield ['unit-enum', [FooUnitEnum::Bar], true];
253+
yield ['readonly', new FooReadonly('k', 'v')];
250254
}
251255

252256
public function testUnicodeDirectionality()

0 commit comments

Comments
 (0)