Skip to content

[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

Conversation

ngirardet-mob
Copy link

@ngirardet-mob ngirardet-mob commented Mar 14, 2025

Attempt to fix issue #11871

Summary : When an entity is associated with a class declaring private(set) properties. The proxyFactory does not ignore those properties as it does with privates one. This leads to an error such as "Error: Cannot unset private(set) property ".

@ngirardet-mob ngirardet-mob marked this pull request as ready for review March 14, 2025 12:59

#[ORM\Entity]
#[ORM\Table(name: 'DDC11871_Order')]
class DDC11871Order
Copy link
Member

Choose a reason for hiding this comment

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

Please inline the classes into the Test or create a new modelset.

Copy link
Author

Choose a reason for hiding this comment

The 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"?

Comment on lines +268 to +272
if (version_compare(PHP_VERSION, '8.4', '<')) {
continue;
} elseif ($property->isPrivateSet() === false) {
continue;
}
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.

@beberlei
Copy link
Member

I think similar to property hooks, use of private(set) should be completly forbidden for now at metadata parse time.

We need to write a positive test, probably only working in conjunction with #11853 . before allowing use.

@ngirardet-mob
Copy link
Author

I think similar to property hooks, use of private(set) should be completly forbidden for now at metadata parse time.

We need to write a positive test, probably only working in conjunction with #11853 . before allowing use.

Do you have any estimate to have property hook ready to deploy ?
This patch could be quick win to gain a little PHP 8.4 compatibility while waiting for #11853.

Ignore phpcs validation as it doesn't support property(set) yet.
@beberlei
Copy link
Member

This skip will break lazy loading, accessing a private set property would not trigger ir

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 19, 2025

Can you try if this issue exists when using the dev version of var-exporter?
I'm not sure this is a concern that should be dealt with on the Doctrine side, and I've been fixing support for asym-vis recently.

@ngirardet-mob
Copy link
Author

@nicolas-grekas Works fine with 7.2x-dev and 7.3.x-dev 😃
Seems to me like this request can be closed and wait until stable release of symfony/var-exporter 7.2.
Thanks to both of you for good work :)

@beberlei beberlei closed this Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants