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
Open
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
11 changes: 8 additions & 3 deletions reference/pdo/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,18 @@
<listitem>
<simpara>
Specifies that the fetch method shall return a new instance of the
requested class, mapping the columns to named properties in the class.
requested class.
</simpara>
<note>
<simpara>
The magic
The object is initialized by mapping the columns from the result set to
properties in the class. This process occurs before the constructor is
called, allowing the population of properties regardless of their
visibility or whether they are marked as <literal>readonly</literal>. If
a property does not exist in the class, the magic
<link linkend="language.oop5.overloading.members"><methodname>__set</methodname></link>
method is called if the property doesn't exist in the requested class
method will be invoked if it exists; otherwise, a dynamic public property
will be created.
</simpara>
</note>
</listitem>
Expand Down
19 changes: 12 additions & 7 deletions reference/pdo/pdostatement/fetch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@
</para></listitem>
<listitem><para>
<literal>PDO::FETCH_CLASS</literal>: returns a new instance of the
requested class, mapping the columns of the result set to named
properties in the class, and calling the constructor afterwards, unless
<literal>PDO::FETCH_PROPS_LATE</literal> is also given.
If <parameter>mode</parameter>
includes PDO::FETCH_CLASSTYPE (e.g. <literal>PDO::FETCH_CLASS |
PDO::FETCH_CLASSTYPE</literal>) then the name of the class is
determined from a value of the first column.
requested class. The object is initialized by mapping the columns of
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?

method will be invoked if it exists; otherwise, a dynamic public
property will be created. If <literal>PDO::FETCH_PROPS_LATE</literal>
is also given, the constructor is called <emphasis>before</emphasis>
the properties are populated. If <parameter>mode</parameter> includes
<literal>PDO::FETCH_CLASSTYPE</literal> (e.g.
<literal>PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE</literal>), the name
of the class is determined from the value of the first column.
</para></listitem>
<listitem><para>
<literal>PDO::FETCH_INTO</literal>: updates an existing instance
Expand Down
Loading