note 97973 added to pdostatement.fetchall
| From: | esw at pixeloution dot removeme dot com | Date: | Wed, 19 May 2010 04:17:43 +0000 |
| Subject: | note 97973 added to pdostatement.fetchall | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169387@lists.php.net to get a copy of this message | ||
Interestingly enough, when you use fetchAll, the constructor for your object is called AFTER the
properties are assigned. For example:
<?php
class person {
public $name;
function __construct() {
$this->name = $this->name . " is my name.";
}
}
# set up select from a database here with PDO
$obj = $STH->fetchALL(PDO::FETCH_CLASS, 'person');
?>
Will result in ' is my name' being appended to all the name columns. However if you call
it slightly differently:
<?php
$obj = $obj = $STH->fetchAll(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'person');
?>
Then the constructor will be called before properties are assigned. I can't find this
documented anywhere, so I thought it would be nice to add a note here.
----
Server IP: 208.69.120.55
Probable Submitter: 68.58.70.221
----
Manual Page -- http://www.php.net/manual/en/pdostatement.fetchall.php
Edit -- https://master.php.net/note/edit/97973
Del: integrated -- https://master.php.net/note/delete/97973/integrated
Del: useless -- https://master.php.net/note/delete/97973/useless
Del: bad code -- https://master.php.net/note/delete/97973/bad+code
Del: spam -- https://master.php.net/note/delete/97973/spam
Del: non-english -- https://master.php.net/note/delete/97973/non-english
Del: in docs -- https://master.php.net/note/delete/97973/in+docs
Del: other reasons-- https://master.php.net/note/delete/97973
Reject -- https://master.php.net/note/reject/97973
Search -- https://master.php.net/manage/user-notes.php