diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/LazyObject.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/LazyObject.php new file mode 100644 index 0000000000000..eb48122d2d004 --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/LazyObject.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests\Fixtures; + +use Symfony\Component\VarExporter\LazyGhostTrait; + +class LazyObject +{ + use LazyGhostTrait; + + public bool $readableProperty; + + public function __construct() + { + self::createLazyGhost(initializer: $this->hydrate(...), instance: $this); + } + + private function hydrate(): void + { + $this->readableProperty = true; + } +} diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index fc9844944c66e..df21257a233d1 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -21,6 +21,7 @@ use Symfony\Component\PropertyAccess\PropertyAccessor; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\PropertyAccess\Tests\Fixtures\ExtendedUninitializedProperty; +use Symfony\Component\PropertyAccess\Tests\Fixtures\LazyObject; use Symfony\Component\PropertyAccess\Tests\Fixtures\ReturnTyped; use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidArgumentLength; use Symfony\Component\PropertyAccess\Tests\Fixtures\TestAdderRemoverInvalidMethods; @@ -465,6 +466,14 @@ public function testIsReadableRecognizesMagicCallIfEnabled() $this->assertTrue($this->propertyAccessor->isReadable(new TestClassMagicCall('Bernhard'), 'magicCallProperty')); } + public function testIsReadableReturnsFalseIfInitializedLazyObjectPropertyDoesNotExist() + { + $object = new LazyObject(); + $object->initializeLazyObject(); + + $this->assertFalse($this->propertyAccessor->isReadable($object, 'nonExistentProperty')); + } + /** * @dataProvider getValidWritePropertyPaths */ diff --git a/src/Symfony/Component/PropertyAccess/composer.json b/src/Symfony/Component/PropertyAccess/composer.json index ce7710cfe187d..8882675220a8c 100644 --- a/src/Symfony/Component/PropertyAccess/composer.json +++ b/src/Symfony/Component/PropertyAccess/composer.json @@ -21,7 +21,8 @@ "symfony/property-info": "^5.4|^6.0|^7.0" }, "require-dev": { - "symfony/cache": "^5.4|^6.0|^7.0" + "symfony/cache": "^5.4|^6.0|^7.0", + "symfony/var-exporter": "^6.2|^7.0" }, "autoload": { "psr-4": { "Symfony\\Component\\PropertyAccess\\": "" },
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: