diff --git a/src/Proxy/ProxyFactory.php b/src/Proxy/ProxyFactory.php index b2d114a6698..85a7c23711e 100644 --- a/src/Proxy/ProxyFactory.php +++ b/src/Proxy/ProxyFactory.php @@ -43,8 +43,10 @@ use function strtr; use function substr; use function ucfirst; +use function version_compare; use const DIRECTORY_SEPARATOR; +use const PHP_VERSION; /** * This factory is used to create proxy objects for entities at runtime. @@ -263,7 +265,11 @@ private function getProxyFactory(string $className): Closure $name = $property->name; if ($property->isStatic() || (($class->hasField($name) || $class->hasAssociation($name)) && ! isset($identifiers[$name]))) { - continue; + if (version_compare(PHP_VERSION, '8.4', '<')) { + continue; + } elseif ($property->isPrivateSet() === false) { + continue; + } } $prefix = $property->isPrivate() ? "\0" . $property->class . "\0" : ($property->isProtected() ? "\0*\0" : ''); diff --git a/tests/Tests/ORM/Functional/Ticket/DDC11871Test.php b/tests/Tests/ORM/Functional/Ticket/DDC11871Test.php new file mode 100644 index 00000000000..fe026142752 --- /dev/null +++ b/tests/Tests/ORM/Functional/Ticket/DDC11871Test.php @@ -0,0 +1,84 @@ +setUpEntitySchema([ + DDC11871User::class, + DDC11871Order::class, + ]); + } + + public function testEntityHydratation(): void + { + $user = new DDC11871User('Some company'); + $this->_em->persist($user); + $order = new DDC11871Order($user); + $this->_em->persist($order); + $this->_em->flush(); + $this->_em->clear(); + + $hydrated = $this->_em->getRepository(DDC11871Order::class)->findAll(); + self::assertCount(1, $hydrated); + } +} + +#[ORM\Entity] +#[ORM\Table(name: 'DDC11871_User')] +class DDC11871User +{ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] + public int $id; + + #[ORM\Column(type: 'string')] + private(set) string $company; // phpcs:ignore + + public function __construct(string $company) + { + $this->company = $company; + } +} + +#[ORM\Entity] +#[ORM\Table(name: 'DDC11871_Order')] +class DDC11871Order +{ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] + public int $id; + + #[ORM\Column] + private(set) string $company; // phpcs:ignore + + public function __construct( + #[ORM\ManyToOne(targetEntity: DDC11871User::class, fetch: 'LAZY')] + private(set) DDC11871User $user, // phpcs:ignore + ) { + $this->company = $user->company; + } +}