|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61843 mysqli fetch_object calls __set() before __construct()
Submitted: 2012-04-24 19:45 UTC Modified: 2012-04-24 21:35 UTC
From: jdolieslager at gmail dot com Assigned:
Status: Wont fix Package: MySQLi related
PHP Version: 5.3.10 OS: Windows 7 x64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-04-24 19:45 UTC] jdolieslager at gmail dot com
I retrieve a record from the database and want to store into an object. This will be a dataobject that does basically validate the values. I noticed that the constructor will be called after the magic function __set has been called. This should be the other way around.

=============== SYSTEM INFO ==================

System 	Windows NT JESPER-LT 6.1 build 7601 (Windows 7 Ultimate Edition Service Pack 1) i586
Build Date 	Feb 2 2012 20:26:31
Compiler 	MSVC9 (Visual C++ 2008)
Architecture 	x86
Configure Command 	cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--disable-isapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static" "--disable-static-analyze" 


================ MYSQLI =======================
MysqlI Support	enabled
Client API library version 	mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $
Active Persistent Links 	0
Inactive Persistent Links 	0
Active Links 	0

Directive	Local Value	Master Value
mysqli.allow_local_infile	On	On
mysqli.allow_persistent	On	On
mysqli.default_host	no value	no value
mysqli.default_port	3306	3306
mysqli.default_pw	no value	no value
mysqli.default_socket	no value	no value
mysqli.default_user	no value	no value
mysqli.max_links	Unlimited	Unlimited
mysqli.max_persistent	Unlimited	Unlimited
mysqli.reconnect	Off	Off


Beneath you'll find a basic example of the bug. 

The database structure I use for this example:
CREATE TABLE `users` (
	`username` VARCHAR(50) NOT NULL,
	`password` VARCHAR(50) NOT NULL,
	PRIMARY KEY (`id`),
	UNIQUE INDEX `username` (`username`)

Test script:
class foo {
    function __construct() {
        echo '__construct() <br />';
    function __set($key, $value) {
        echo '__set() <br />';

$mysql = new mysqli('', 'root', '', 'test');
$rs = $mysql->query('SELECT id, username, password FROM users');
$obj = $rs->fetch_object('foo');

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-24 19:49 UTC] jdolieslager at gmail dot com
** Changed to correct package category
 [2012-04-24 19:49 UTC] jdolieslager at gmail dot com
-Package: mysql +Package: MySQLi related
 [2012-04-24 21:35 UTC]
-Status: Open +Status: Wont fix
 [2012-04-24 21:35 UTC]
Unfortunately we can't fix this as many people depend on the current behavior where people can access the data from within the constructor.

If you check history this wasactually "fixed" once but then reverted.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Dec 06 15:03:34 2021 UTC