|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72184 mysqli_result::fetch_object initializes properties after constructor call
Submitted: 2016-05-10 09:24 UTC Modified: 2016-05-10 09:26 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: php at fleshgrinder dot com Assigned:
Status: Duplicate Package: MySQLi related
PHP Version: 7.0.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at fleshgrinder dot com
New email:
PHP Version: OS:


 [2016-05-10 09:24 UTC] php at fleshgrinder dot com
> Note that **mysqli_fetch_object()** sets the properties of the object before calling the object constructor.
> ---

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();
$r = $c->query('SELECT 21 AS `x`, 42 AS `y`, 84 AS `z`');
while (($o = $r->fetch_object(Test::class))) {

Expected result:
string(2) "21"
string(2) "42"
string(2) "84"
object(Test)#3 (3) {
  string(2) "21"
  string(2) "42"
  string(2) "84"

Actual result:
object(Test)#3 (3) {
  string(2) "21"
  string(2) "42"
  string(2) "84"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-10 09:26 UTC]
-Status: Open +Status: Duplicate
 [2016-05-10 09:26 UTC]
See bug #72151.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Dec 05 01:03:35 2021 UTC