|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-06 20:33 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 20:00:01 2025 UTC |
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; } }ircmaxwell@php.net: Are you sure that this has never been released? In PHP 5.2.17 I see this exact behaviour. Testcase: <?php class TestClass { public function __construct() { echo 'construct'."\n"; } public function __set($key, $value) { echo 'set "'.$key.'" to "'.$value . '"' ."\n"; } } $db = new mysqli(); $db->query('SELECT "PHP" as name')->fetch_object('TestClass'); Expected output (as documented): set "name" to "PHP" construct Actual output: construct set "name" to "PHP"