Req #73397 [NEW]: Add FETCH_CLASS_VIA_CONSTRUCTOR fetch mode

From: Date: Wed, 26 Oct 2016 20:58:28 +0000
Subject: Req #73397 [NEW]: Add FETCH_CLASS_VIA_CONSTRUCTOR fetch mode
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205033@lists.php.net to get a copy of this message
From: tomas dot fejfar at gmail dot com Operating system: N/A PHP version: Irrelevant Package: PDO related Bug Type: Feature/Change Request Bug description:Add FETCH_CLASS_VIA_CONSTRUCTOR fetch mode Description: ------------ PDO allows property injection, but not creation via constructor. That forces the developer to do extra work to ensure that the created object is not in inconsistent state. If there was FETCH_CLASS_VIA_CONSTRUCTOR fetch mode PDO would be much closer to being a very simple ORM and much easier to use for people not using a special DB framework. Not that I currently absolutely need it because there is workaround, but I think it would be a nice addition. Expected result: ---------------- $results = $stms->fetchAll(PDO::FETCH_CLASS_VIA_CONSTRUCTOR, Task::class); Actual result: -------------- while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $results[] = new Task($row['id'], $row['name']); } //or $stmt->fetchAll(PDO::FETCH_FUNC, function ($id, $name) { return new Task($id, $name); }); -- Edit bug report at https://bugs.php.net/bug.php?id=73397&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73397&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73397&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73397&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73397&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73397&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73397&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73397&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73397&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73397&r=support Expected behavior: https://bugs.php.net/fix.php?id=73397&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73397&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73397&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73397&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73397&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73397&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73397&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73397&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73397&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73397&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73397&r=mysqlcfg

« previous php.bugs (#205033) next »