ID: 50636 Updated by: pierr...@php.net Reported By: stein at rhrk dot uni-kl dot de -Status: Open +Status: Closed Bug Type: MySQLi related Operating System: * PHP Version: 5.2.12 New Comment:
This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2010-01-03 16:59:34] s...@php.net Automatic comment from SVN on behalf of pierrick Revision: http://svn.php.net/viewvc/?view=revision&revision=293039 Log: Fixed bug #50636 (MySQLi_Result sets values before calling constructor) ------------------------------------------------------------------------ [2010-01-02 15:03:49] stein at rhrk dot uni-kl dot de Description: ------------ MySQLi_Result::fetch_object sets properties before calling the constructor, see BUG #49521 The behavior is similar to the one in BUG #49521 which has been fixed as of PHP 5.2.12. Note: It should be considered that this behavior may be not bug at all. Calling the constructor BEFORE setting the properties (as done in BUG #49521) leaves no possibility to work with the data at "construction time" of the object. Setting default properties could be done by assigning them in the class-definition, but setting other properties depending on the loaded data is hard to do, when this data is not yet available when the constructor is called. This problem is even harder to solve, as no setters for the properties are called, even if they are declared as private. Reproduce code: --------------- class Test { private $myprivate = 0; function __construct() { echo 'constructor called, $myprivate is ', $this->myprivate; } function __set ( $name, $value ) { echo 'setting ', $name, ' to ', $value; $this->{$name} = (int) $value; } } $mysqli->query('SELECT 1 AS myprivate, 2 AS mypublic')->fetch_object('Test'); Expected result: ---------------- If the same way to handle this bug as in BUG #49521 is considered: constructor called, $myprivate is 0 setting mypublic to 2 object(Test)#6 (2) { ["myprivate:private"]=> string(1) "1" ["mypublic"]=> int(2) } But maybe the following behavior would make more sense if it should be changed: constructor called, $myprivate is 0 setting myprivate to 1 setting mypublic to 2 object(Test)#6 (2) { ["myprivate:private"]=> int(1) ["mypublic"]=> int(2) } Actual result: -------------- setting mypublic to 2 constructor called, $myprivate is 1 object(Test)#6 (2) { ["myprivate:private"]=> string(1) "1" ["mypublic"]=> int(2) } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50636&edit=1