Skip to content
Closed
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
8 changes: 7 additions & 1 deletion src/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Comment on lines +268 to +272
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic looks wrong, it only skips private set fields in PHP 8.4+ - but not others anymore.

Should maybe be:

if ($property->isStatic() || (($class->hasField($name) || $class->hasAssociation($name)) && ! isset($identifiers[$name])) || (PHP_VERSION_ID >= 80400 && $property->isPrivateSet())) {
    continue;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to write a test making sure which properties are skipped. I'll get back to you shortly.

}

$prefix = $property->isPrivate() ? "\0" . $property->class . "\0" : ($property->isProtected() ? "\0*\0" : '');
Expand Down
84 changes: 84 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/DDC11871Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\EventManager;

Check failure on line 7 in tests/Tests/ORM/Functional/Ticket/DDC11871Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Type Doctrine\Common\EventManager is not used in this file.
use Doctrine\DBAL\Connection;

Check failure on line 8 in tests/Tests/ORM/Functional/Ticket/DDC11871Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Type Doctrine\DBAL\Connection is not used in this file.
use Doctrine\DBAL\Platforms\AbstractPlatform;

Check failure on line 9 in tests/Tests/ORM/Functional/Ticket/DDC11871Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Type Doctrine\DBAL\Platforms\AbstractPlatform is not used in this file.
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Proxy\ProxyFactory;

Check failure on line 11 in tests/Tests/ORM/Functional/Ticket/DDC11871Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Type Doctrine\ORM\Proxy\ProxyFactory is not used in this file.
use Doctrine\Tests\Mocks\EntityManagerMock;

Check failure on line 12 in tests/Tests/ORM/Functional/Ticket/DDC11871Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Type Doctrine\Tests\Mocks\EntityManagerMock is not used in this file.
use Doctrine\Tests\Mocks\UnitOfWorkMock;

Check failure on line 13 in tests/Tests/ORM/Functional/Ticket/DDC11871Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (PHP: 8.4)

Type Doctrine\Tests\Mocks\UnitOfWorkMock is not used in this file.
use Doctrine\Tests\OrmFunctionalTestCase;

use const PHP_VERSION_ID;

class DDC11871Test extends OrmFunctionalTestCase
{
public function setUp(): void
{
parent::setUp();

if (PHP_VERSION_ID < 80400) {
self::markTestSkipped('The ' . self::class . ' requires PHP 8.4.');
}

$this->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;
}
}
Loading