|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests |
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 05:00:02 2025 UTC |
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); });