From: stein at rhrk dot uni-kl dot de Operating system: PHP version: 5.2.12 PHP Bug Type: MySQLi related Bug description: MySQLi_Result sets values before calling constructor
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 bug report at http://bugs.php.net/?id=50636&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50636&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50636&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50636&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50636&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50636&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50636&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50636&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50636&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50636&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50636&r=support Expected behavior: http://bugs.php.net/fix.php?id=50636&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50636&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50636&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50636&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50636&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50636&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50636&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50636&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50636&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50636&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50636&r=mysqlcfg