#48487 [Com]: fetch_object calls __set before constructor
| From: | caferrari at gmail dot com | Date: | Fri, 06 Nov 2009 16:29:19 +0000 |
| Subject: | #48487 [Com]: fetch_object calls __set before constructor | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144318@lists.php.net to get a copy of this message | ||
ID: 48487
Comment by: caferrari at gmail dot com
Reported By: joel at purerave dot com
Status: Open
Bug Type: MySQLi related
Operating System: win2k sp4
PHP Version: 5.2.9
New Comment:
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;
}
}
Previous Comments:
------------------------------------------------------------------------
[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