Skip to content
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

PDO(FETCH_CLASS): private and read-only properties are populated too #4360

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pereorga
Copy link
Contributor

@pereorga pereorga commented Jan 5, 2025

I'm not sure if this behavior is intentional, but it's something I rely on.

@@ -243,6 +243,7 @@
<simpara>
Specifies that the fetch method shall return a new instance of the
requested class, mapping the columns to named properties in the class.
Private and read-only properties will also be populated.
Copy link
Member

Choose a reason for hiding this comment

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

You are correct, but why wouldn't it fill private and readonly properties? I guess the current description is a bit unclear and misleading.

mapping the columns to named properties in the class

That's not even true. If a property doesn't exist it will call __set and if that doesn't exist it will create a dynamic public property.

The object is created with the properties populated before even the constructor is called. The visibility doesn't matter. And when the object is created the property has never been written to before so readonly doesn't matter either.

I can merge it as you propose but I feel like we could do better here. However, I am incapable of doing it better myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback. I’ve tried to improve the explanation. Please let me know if it is correct

the result set to properties in the class. This occurs before the
constructor is called, allowing properties to be populated regardless
of their visibility or whether they are marked as <literal>readonly</literal>.
If a property does not exist in the class, the magic <methodname>__set</methodname>
Copy link
Member

Choose a reason for hiding this comment

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

@Girgias Do you know if we can use methodname with __set? The other one in this PR links to a different page. I think all the other ones in the repo link to <link linkend="object.set">__set()</link>. What's the correct approach?

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.

2 participants