8000 minor #48306 [VarExporter] List required properties in lazy traits (n… · symfony/symfony@9eafa3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 9eafa3e

Browse files
minor #48306 [VarExporter] List required properties in lazy traits (nicolas-grekas)
This PR was merged into the 6.2 branch. Discussion ---------- [VarExporter] List required properties in lazy traits | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - At first I decided to not list those properties to work around limitations of readonly classes. By listing properties as proposed here, we make the lazy traits incompatible with readonly classes. But 1. declaring those properties in consumers is a WTF, and 2. the issues with readonly classes are likely going to be removed in PHP 8.3 after https://wiki.php.net/rfc/readonly_amendments Commits ------- 1e1f3a5 [VarExporter] List required properties in lazy traits
2 parents 521d210 + 1e1f3a5 commit 9eafa3e

19 files changed

+15
-53
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class Redis5Proxy extends \Redis implements ResetInterface, LazyObjectInterface
2929
resetLazyObject as reset;
3030
}
3131

32-
private int $lazyObjectId;
33-
private \Redis $lazyObjectReal;
34-
3532
private const LAZY_OBJECT_PROPERTY_SCOPES = [
3633
'lazyObjectReal' => [self::class, 'lazyObjectReal', null],
3734
"\0".self::class."\0lazyObjectReal" => [self::class, 'lazyObjectReal', null],

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class Redis6Proxy extends \Redis implements ResetInterface, LazyObjectInterface
2929
resetLazyObject as reset;
3030
}
3131

32-
private int $lazyObjectId;
33-
private \Redis $lazyObjectReal;
34-
3532
private const LAZY_OBJECT_PROPERTY_SCOPES = [
3633
'lazyObjectReal' => [self::class, 'lazyObjectReal', null],
3734
"\0".self::class."\0lazyObjectReal" => [self::class, 'lazyObjectReal', null],

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class RedisCluster5Proxy extends \RedisCluster implements ResetInterface, LazyOb
2929
resetLazyObject as reset;
3030
}
3131

32-
private int $lazyObjectId;
33-
private \RedisCluster $lazyObjectReal;
34-
3532
private const LAZY_OBJECT_PROPERTY_SCOPES = [
3633
'lazyObjectReal' => [self::class, 'lazyObjectReal', null],
3734
"\0".self::class."\0lazyObjectReal" => [self::class, 'lazyObjectReal', null],

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyOb
2929
resetLazyObject as reset;
3030
}
3131

32-
private int $lazyObjectId;
33-
private \RedisCluster $lazyObjectReal;
34-
3532
private const LAZY_OBJECT_PROPERTY_SCOPES = [
3633
'lazyObjectReal' => [self::class, 'lazyObjectReal', null],
3734
"\0".self::class."\0lazyObjectReal" => [self::class, 'lazyObjectReal', null],

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dedup_lazy_ghost.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ class stdClass_5a8a5eb extends \stdClass implements \Symfony\Component\VarExport
7575
{
7676
use \Symfony\Component\VarExporter\LazyGhostTrait;
7777

78-
private int $lazyObjectId;
79-
8078
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
8179
}
8280

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_as_files.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class FooLazyClass_f814e3a extends \Bar\FooLazyClass implements \Symfony\Compone
4545
{
4646
use \Symfony\Component\VarExporter\LazyGhostTrait;
4747

48-
private int $lazyObjectId;
49-
5048
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
5149
}
5250

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_ghost.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class stdClass_5a8a5eb extends \stdClass implements \Symfony\Component\VarExport
7979
{
8080
use \Symfony\Component\VarExporter\LazyGhostTrait;
8181

82-
private int $lazyObjectId;
83-
8482
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
8583
}
8684

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ class Wither_94fa281 extends \Symfony\Component\DependencyInjection\Tests\Compil
7575
{
7676
use \Symfony\Component\VarExporter\LazyProxyTrait;
7777

78-
private int $lazyObjectId;
79-
private parent $lazyObjectReal;
80-
8178
private const LAZY_OBJECT_PROPERTY_SCOPES = [
8279
'lazyObjectReal' => [self::class, 'lazyObjectReal', null],
8380
"\0".self::class."\0lazyObjectReal" => [self::class, 'lazyObjectReal', null],

src/Symfony/Component/VarExporter/LazyGhostTrait.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
use Symfony\Component\VarExporter\Internal\LazyObjectRegistry as Registry;
1616
use Symfony\Component\VarExporter\Internal\LazyObjectState;
1717

18-
/**
19-
* @property int $lazyObjectId This property must be declared as private in classes using this trait
20-
*/
2118
trait LazyGhostTrait
2219
{
20+
private int $lazyObjectId;
21+
2322
/**
2423
* Creates a lazy-loading ghost instance.
2524
*
@@ -31,6 +30,9 @@ trait LazyGhostTrait
3130
* initialize, the property to initialize, its write-scope, and its default
3231
* value. Each closure should return the value of the corresponding property.
3332
*
33+
* Properties should be indexed by their array-cast name, see
34+
* https://php.net/manual/language.types.array#language.types.array.casting
35+
*
3436
* @param \Closure(static):void|array<string, \Closure(static, string, ?string, mixed):mixed> $initializer
3537
* @param array<string, true> $skippedProperties An array indexed by the properties to skip, aka the ones
3638
* that the initializer doesn't set when its a closure

src/Symfony/Component/VarExporter/LazyProxyTrait.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
use Symfony\Component\VarExporter\Internal\LazyObjectRegistry as Registry;
1717
use Symfony\Component\VarExporter\Internal\LazyObjectState;
1818

19-
/**
20-
* @property int $lazyObjectId This property must be declared as private in classes using this trait
21-
* @property parent $lazyObjectReal This property must be declared as private in classes using this trait;
22-
* its type should match the type of the proxied object
23-
*/
2419
trait LazyProxyTrait
2520
{
21+
private int $lazyObjectId;
22+
private object $lazyObjectReal;
23+
2624
/**
2725
* Creates a lazy-loading virtual proxy.
2826
*

0 commit comments

Comments
 (0)
0