[prev in list] [next in list] [prev in thread] [next in thread]
List: php-doc-cvs
Subject: [DOC-CVS] =?utf-8?q?svn:_/phpdoc/en/trunk/reference/pdo/pdostatement/_fetch.xml_fetchobject.xml?=
From: Christoph_Michael_Becker <cmb () php ! net>
Date: 2016-06-29 11:03:39
Message-ID: svn-cmb-1467198219-339520-1150959622 () svn ! php ! net
[Download RAW message or body]
cmb Wed, 29 Jun 2016 11:03:39 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=339520
Log:
Fix #53394: Insufficient docs regarding PDOStatement::fetch(Object) and constructors
Bug: https://bugs.php.net/53394 (Verified) Insufficient docs regarding \
PDOStatement::fetch(Object) and constructors
Changed paths:
U phpdoc/en/trunk/reference/pdo/pdostatement/fetch.xml
U phpdoc/en/trunk/reference/pdo/pdostatement/fetchobject.xml
Modified: phpdoc/en/trunk/reference/pdo/pdostatement/fetch.xml
===================================================================
--- phpdoc/en/trunk/reference/pdo/pdostatement/fetch.xml 2016-06-29 00:05:06 UTC (rev \
339519)
+++ phpdoc/en/trunk/reference/pdo/pdostatement/fetch.xml 2016-06-29 11:03:39 UTC (rev \
339520) @@ -54,7 +54,9 @@
<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. If <parameter>fetch_style</parameter>
+ properties in the class, and calling the constructor afterwards, unless
+ <literal>PDO::FETCH_PROPS_LATE</literal> is also given.
+ If <parameter>fetch_style</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.
@@ -85,6 +87,12 @@
property names that correspond to the column names returned in your
result set
</para></listitem>
+ <listitem><para>
+ <literal>PDO::FETCH_PROPS_LATE</literal>: when used with
+ <literal>PDO::FETCH_CLASS</literal>, the constructor of the class is
+ called before the properties are assigned from the respective column
+ values.
+ </para></listitem>
</itemizedlist>
</para>
</listitem>
@@ -262,6 +270,56 @@
</screen>
</example>
+ <example><title>Construction order</title>
+ <simpara>
+ When objects are fetched via <literal>PDO::FETCH_CLASS</literal> the object
+ properties are assigned first, and then the constructor of the class is
+ invoked. If <literal>PDO::FETCH_PROPS_LATE</literal> is also given, this
+ order is reversed, i.e. first the constructor is called, and afterwards the
+ properties are assigned.
+ </simpara>
+ <programlisting role="php">
+<![CDATA[
+<?php
+class Person
+{
+ private $name;
+
+ public function __construct()
+ {
+ $this->tell();
+ }
+
+ public function tell()
+ {
+ if (isset($this->name)) {
+ echo "I am {$this->name}.\n";
+ } else {
+ echo "I don't have a name yet.\n";
+ }
+ }
+}
+
+$sth = $dbh->query("SELECT * FROM people");
+$sth->setFetchMode(PDO::FETCH_CLASS, 'Person');
+$person = $sth->fetch();
+$person->tell();
+$sth->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, 'Person');
+$person = $sth->fetch();
+$person->tell();
+?>
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+I am Alice.
+I am Alice.
+I don't have a name yet.
+I am Bob.
+]]>
+ </screen>
+ </example>
</para>
</refsect1>
Modified: phpdoc/en/trunk/reference/pdo/pdostatement/fetchobject.xml
===================================================================
--- phpdoc/en/trunk/reference/pdo/pdostatement/fetchobject.xml 2016-06-29 00:05:06 \
UTC (rev 339519)
+++ phpdoc/en/trunk/reference/pdo/pdostatement/fetchobject.xml 2016-06-29 11:03:39 \
UTC (rev 339520) @@ -19,6 +19,10 @@
<constant>PDO::FETCH_CLASS</constant> or
<constant>PDO::FETCH_OBJ</constant> style.
</para>
+ <para>
+ When an object is fetched, its properties are assigned from respective
+ column values, and afterwards its constructor is invoked.
+ </para>
</refsect1>
<refsect1 role="parameters">
--
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic