diff --git a/lib/Doctrine/Common/Proxy/ProxyGenerator.php b/lib/Doctrine/Common/Proxy/ProxyGenerator.php index 9ae43b044..ae10f90c0 100644 --- a/lib/Doctrine/Common/Proxy/ProxyGenerator.php +++ b/lib/Doctrine/Common/Proxy/ProxyGenerator.php @@ -1008,7 +1008,7 @@ private function isShortIdentifierGetter($method, ClassMetadata $class) /** * Generates the list of public properties to be lazy loaded, that are writable. * - * @return array + * @return list */ public function getWriteableLazyLoadedPublicPropertiesNames(ClassMetadata $class): array { diff --git a/tests/Doctrine/Tests/Common/Proxy/Php81ReadonlyPublicPropertyType.php b/tests/Doctrine/Tests/Common/Proxy/Php81ReadonlyPublicPropertyType.php new file mode 100644 index 000000000..011cbfa11 --- /dev/null +++ b/tests/Doctrine/Tests/Common/Proxy/Php81ReadonlyPublicPropertyType.php @@ -0,0 +1,13 @@ += 8.1.0 + */ + public function testPhp81ReadonlyPublicProperties() + { + $className = Php81ReadonlyPublicPropertyType::class; + $proxyClassName = 'Doctrine\Tests\Common\ProxyProxy\__CG__\Php81ReadonlyPublicPropertyType'; + + if ( ! class_exists($proxyClassName, false)) { + $metadata = $this->createClassMetadata($className, ['id']); + + $metadata + ->expects($this->any()) + ->method('hasField') + ->will($this->returnCallback(static function ($fieldName) { + return in_array($fieldName, ['id', 'readable', 'writeable']); + })); + + $proxyGenerator = new ProxyGenerator(__DIR__ . '/generated', __NAMESPACE__ . 'Proxy'); + $this->generateAndRequire($proxyGenerator, $metadata); + } + + // Readonly properties are removed from unset. + self::assertStringContainsString( + 'unset($this->writeable);', + file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp81ReadonlyPublicPropertyType.php') + ); + + // But remain in property listings. + self::assertStringContainsString( + "'readable' => NULL", + file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp81ReadonlyPublicPropertyType.php') + ); + } + /** * @requires PHP >= 8.1.0 */