php.net |  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
Votes:1
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
33 - 10 = ?
Subscribe to this entry?

 
 [2016-05-10 09:24 UTC] php at fleshgrinder dot com
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"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-10 09:26 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2016-05-10 09:26 UTC] requinix@php.net
See bug #72151.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC