Skip to content

Commit 3b8692f

Browse files
kbondnicolas-grekas
authored andcommitted
add reproducer
1 parent c9efc1c commit 3b8692f

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

lib/Doctrine/ORM/Proxy/ProxyFactory.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,10 @@ private function generateSkippedProperties(ClassMetadata $class): string
314314
{
315315
$skippedProperties = ['__isCloning' => true];
316316
$identifiers = array_flip($class->getIdentifierFieldNames());
317+
$filter = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE;
318+
$reflector = $class->getReflectionClass();
317319

318-
$filter = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE;
319-
$reflector = $class->getReflectionClass();
320-
321-
do {
320+
while ($reflector) {
322321
foreach ($reflector->getProperties($filter) as $property) {
323322
$name = $property->getName();
324323

@@ -330,8 +329,10 @@ private function generateSkippedProperties(ClassMetadata $class): string
330329

331330
$skippedProperties[$prefix . $name] = true;
332331
}
333-
$filter = ReflectionProperty::IS_PRIVATE;
334-
} while ($reflector = $reflector->getParentClass());
332+
333+
$filter = ReflectionProperty::IS_PRIVATE;
334+
$reflector = $reflector->getParentClass();
335+
}
335336

336337
uksort($skippedProperties, 'strnatcmp');
337338

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\GH10336;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
9+
/**
10+
* @ORM\Entity
11+
* @ORM\Table(name="gh10336_entities")
12+
*/
13+
class GH10336Entity
14+
{
15+
/**
16+
* @ORM\Id
17+
* @ORM\Column(type="integer")
18+
* @ORM\GeneratedValue
19+
*/
20+
public ?int $id = null;
21+
22+
/**
23+
* @ORM\ManyToOne(targetEntity="GH10336Relation")
24+
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id", nullable=true)
25+
*/
26+
public ?GH10336Relation $relation = null;
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\GH10336;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
9+
/**
10+
* @ORM\Entity
11+
* @ORM\Table(name="gh10336_relations")
12+
*/
13+
class GH10336Relation
14+
{
15+
/**
16+
* @ORM\Id
17+
* @ORM\Column(type="integer")
18+
* @ORM\GeneratedValue
19+
*/
20+
public ?int $id = null;
21+
22+
/**
23+
* @ORM\Column(type="string")
24+
*/
25+
public string $value;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket;
6+
7+
use Doctrine\Tests\Models\GH10336\GH10336Entity;
8+
use Doctrine\Tests\Models\GH10336\GH10336Relation;
9+
use Doctrine\Tests\OrmFunctionalTestCase;
10+
11+
/**
12+
* @requires PHP 7.4
13+
*/
14+
final class GH10336Test extends OrmFunctionalTestCase
15+
{
16+
public function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
$this->createSchemaForModels(
21+
GH10336Entity::class,
22+
GH10336Relation::class
23+
);
24+
}
25+
26+
public function testCanAccessRelationPropertyAfterClear(): void
27+
{
28+
$relation = new GH10336Relation();
29+
$relation->value = 'foo';
30+
$entity = new GH10336Entity();
31+
$entity->relation = $relation;
32+
33+
$this->_em->persist($entity);
34+
$this->_em->persist($relation);
35+
$this->_em->flush();
36+
$this->_em->clear();
37+
38+
$entity = $this->_em->find(GH10336Entity::class, 1);
39+
40+
$this->_em->clear();
41+
42+
$this->assertSame('foo', $entity->relation->value);
43+
}
44+
}

0 commit comments

Comments
 (0)