Bug #72184 [NEW]: mysqli_result::fetch_object initializes properties after constructor call

From: Date: Tue, 10 May 2016 09:24:35 +0000
Subject: Bug #72184 [NEW]: mysqli_result::fetch_object initializes properties after constructor call
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200985@lists.php.net to get a copy of this message
From: php at fleshgrinder dot com Operating system: PHP version: 7.0.6 Package: MySQLi related Bug Type: Bug Bug description:mysqli_result::fetch_object initializes properties after constructor call Description: ------------ > Note that **mysqli_fetch_object()** sets the properties of the object before calling the object constructor. > > --- https://secure.php.net/mysqli-result.fetch-object This is how it is described in the manual and how it worked in <7.0.6 but the new patch release introduced a serious BC in this regard. I know that the way the method works is debatable and is being debated in internals, however, breaking this behavior in a patch release is out of question. Test script: --------------- final class Test { public $x; protected $y; private $z; public function __construct() { var_dump($this->x, $this->y, $this->z); } } $c = new mysqli(); $c->real_connect(); $c->select_db('test'); $r = $c->query('SELECT 21 AS x, 42 AS y, 84 AS z'); while (($o = $r->fetch_object(Test::class))) { var_dump($o); } $r->close(); $c->close(); Expected result: ---------------- string(2) "21" string(2) "42" string(2) "84" object(Test)#3 (3) { ["x"]=> string(2) "21" ["y":protected]=> string(2) "42" ["z":"Test":private]=> string(2) "84" } Actual result: -------------- NULL NULL NULL object(Test)#3 (3) { ["x"]=> string(2) "21" ["y":protected]=> string(2) "42" ["z":"Test":private]=> string(2) "84" } -- Edit bug report at https://bugs.php.net/bug.php?id=72184&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72184&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72184&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72184&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72184&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72184&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72184&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72184&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72184&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72184&r=support Expected behavior: https://bugs.php.net/fix.php?id=72184&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72184&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72184&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72184&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72184&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72184&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72184&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72184&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72184&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72184&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72184&r=mysqlcfg

« previous php.bugs (#200985) next »