Bug #72184 [Opn->Dup]: mysqli_result::fetch_object initializes properties after constructor call
| From: | requinix@php.net | Date: | Tue, 10 May 2016 09:26:25 +0000 |
| Subject: | Bug #72184 [Opn->Dup]: mysqli_result::fetch_object initializes properties after constructor call | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200986@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72184&edit=1
ID: 72184
Updated by: requinix@php.net
Reported by: php at fleshgrinder dot com
Summary: mysqli_result::fetch_object initializes properties
after constructor call
-Status: Open
+Status: Duplicate
Type: Bug
Package: MySQLi related
PHP Version: 7.0.6
Block user comment: N
Private report: N
New Comment:
See bug #72151.
Previous Comments:
------------------------------------------------------------------------
[2016-05-10 09:24:30] 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"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72184&edit=1