-
Notifications
You must be signed in to change notification settings - Fork 757
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
base: master
Are you sure you want to change the base?
PDO(FETCH_CLASS): private and read-only properties are populated too #4360
Conversation
reference/pdo/constants.xml
Outdated
@@ -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. |
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.
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.
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.
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> |
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.
@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?
I'm not sure if this behavior is intentional, but it's something I rely on.