-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[PHP8.4]private(set) properties should be skipped to avoid resetting values #11872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\DDC11871; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table(name: 'DDC11871_Order')] | ||
class DDC11871Order | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please inline the classes into the Test or create a new modelset. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inlining classes makes tests with PHP < 8.4 failling. What do you mean by "create a new modelset"? |
||
{ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'integer')] | ||
#[ORM\GeneratedValue(strategy: 'AUTO')] | ||
public int $id; | ||
|
||
#[ORM\Column] | ||
private(set) string $company; | ||
|
||
public function __construct( | ||
#[ORM\ManyToOne(targetEntity: DDC11871User::class, fetch: 'LAZY')] | ||
private(set) DDC11871User $user, | ||
) { | ||
$this->company = $user->company; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\DDC11871; | ||
|
||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\DDC11871; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[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; | ||
|
||
public function __construct(string $company) | ||
{ | ||
$this->company = $company; | ||
} | ||
} |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.