php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jdolieslager at gmail dot com
New email:
PHP Version: OS:

 

 [2012-04-24 19:45 UTC] jdolieslager at gmail dot com
Description:
------------
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` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`username` VARCHAR(50) NOT NULL,
	`password` VARCHAR(50) NOT NULL,
	`created` DATETIME NULL DEFAULT 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('127.0.0.1', 'root', '', 'test');
$rs = $mysql->query('SELECT id, username, password FROM users');
$obj = $rs->fetch_object('foo');

Expected result:
----------------
__construct()
__set()
__set()
__set()

Actual result:
--------------
__set()
__set()
__set()
__construct()

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] johannes@php.net
-Status: Open +Status: Wont fix
 [2012-04-24 21:35 UTC] johannes@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 05:01:29 2024 UTC