Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3862,7 +3862,14 @@ private function getAccessibleProperty(ReflectionService $reflService, string $c
{
$reflectionProperty = $reflService->getAccessibleProperty($class, $field);
if ($reflectionProperty !== null && PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) {
$reflectionProperty = new ReflectionReadonlyProperty($reflectionProperty);
$declaringClass = $reflectionProperty->getDeclaringClass()->name;
if ($declaringClass !== $class) {
$reflectionProperty = $reflService->getAccessibleProperty($declaringClass, $field);
}

if ($reflectionProperty !== null) {
$reflectionProperty = new ReflectionReadonlyProperty($reflectionProperty);
}
}

return $reflectionProperty;
Expand Down
36 changes: 36 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH10049/GH10049Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket\GH10049;

use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @requires PHP 8.1
*/
class GH10049Test extends OrmFunctionalTestCase
{
public function setUp(): void
{
parent::setUp();

$this->createSchemaForModels(
ReadOnlyPropertyOwner::class,
ReadOnlyPropertyInheritor::class
);
}

/**
* @doesNotPerformAssertions
*/
public function testInheritedReadOnlyPropertyValueCanBeSet(): void
{
$child = new ReadOnlyPropertyInheritor(10049);
$this->_em->persist($child);
$this->_em->flush();
$this->_em->clear();

$this->_em->find(ReadOnlyPropertyInheritor::class, 10049);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket\GH10049;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class ReadOnlyPropertyInheritor extends ReadOnlyPropertyOwner
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket\GH10049;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\MappedSuperclass
*/
abstract class ReadOnlyPropertyOwner
{
public function __construct(
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
public readonly int $id
) {
}
}