#48487 [Opn->Csd]: fetch_object calls __set before constructor
ID: 48487
Updated by: uw@php.net
Reported By: joel at purerave dot com
-Status: Open
+Status: Closed
Bug Type: MySQLi related
Operating System: win2k sp4
PHP Version: 5.2.9
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.
Fixed with http://news.php.net/php.cvs/61460
Previous Comments:
------------------------------------------------------------------------
[2009-11-06 16:29:19] caferrari at gmail dot com
Help!.. i am having this issue with php 5.2.10 on Ubuntu 9.10 and
Debian 5... and its evil!... my solution:
class Exemplo {
public function __construct($id=0, $nome='', $sigla=''){
if (isset($this->id)) return; //Ugly solution!!! help!
$this->id = $id;
$this->nome = $nome;
$this->sigla = $sigla;
}
}
------------------------------------------------------------------------
[2009-08-25 17:14:42] joel at purerave dot com
No response yet?
------------------------------------------------------------------------
[2009-06-06 20:33:40] joel at purerave dot com
Description:
------------
mysqli_fetch_object with custom class calls __set() before constructor.
Reproduce code:
---------------
<?php
$mysqli = new mysqli("localhost", "root", "root", "test");
class myData {
function __construct($param) {
echo 'creating'.PHP_EOL;
}
function __set($name, $value) {
$this->{$name} = $value;
echo 'setting'.PHP_EOL;
}
}
$sql = "SELECT id FROM test LIMIT 1";
$result = $mysqli->query($sql);
while ($obj = $result->fetch_object('myData', array('data'))) {
}
Expected result:
----------------
creating
setting
Actual result:
--------------
setting
creating
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48487&edit=1
Thread (7 messages)