Req #66355 [NEW]: PDO::FETCH_INTO $this + protected properties throws Fatal error

From: Date: Thu, 26 Dec 2013 15:41:19 +0000
Subject: Req #66355 [NEW]: PDO::FETCH_INTO $this + protected properties throws Fatal error
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183467@lists.php.net to get a copy of this message
From: sjon at hortensius dot net Operating system: archlinux PHP version: 5.5.7 Package: PDO related Bug Type: Feature/Change Request Bug description:PDO::FETCH_INTO $this + protected properties throws Fatal error Description: ------------ I like FETCH_CLASS being able to put stuff in protected properties, but why can't FETCH_INTO do the same (for $this)? Test script: --------------- <?php class User { protected $id; public static function get() { global $db; $q = $db->query("SELECT * FROM User WHERE id = 1"); $q->setFetchMode(PDO::FETCH_CLASS, 'User'); return $q->fetch(); } public function load() { global $db; $q = $db->query("SELECT * FROM User WHERE id = 1"); $q->setFetchMode(PDO::FETCH_INTO, $this); return $q->fetch(); } } $db = new PDO('sqlite::memory:'); $db->exec("CREATE TABLE User(id INTEGER PRIMARY KEY, name TEXT)"); $db->query("INSERT INTO User VALUES(1, 'test')"); // worko var_dump(User::get()); // no-worko $user = new User; var_dump($user->load()); Expected result: ---------------- Both var_dumps should return the same object Actual result: -------------- object(User)#3 (2) { ["id":protected]=> string(1) "1" ["name"]=> string(4) "test" } Fatal error: Cannot access protected property User::$id in /in/DCjXc on line 24 Process exited with code 255. -- Edit bug report at https://bugs.php.net/bug.php?id=66355&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66355&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66355&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66355&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66355&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66355&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66355&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66355&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66355&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66355&r=support Expected behavior: https://bugs.php.net/fix.php?id=66355&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66355&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66355&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66355&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66355&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66355&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66355&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66355&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66355&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66355&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66355&r=mysqlcfg

« previous php.bugs (#183467) next »