From: ninzya at inbox dot lv
Operating system: Windows XP
PHP version: 5.3.0alpha2
PHP Bug Type: MySQL related
Bug description: mysql_fetch_object calls constructor on object after setting
up properties
Description:
------------
when using custom object return through mysql_fetch_object, function
allocates specified in second parameter object, sets up all properties and
then calls constructor. I think this is wrong. Newly instantiated object's
constructor must be called before any other operation on the object is
performed.
Reproduce code:
---------------
/**
* Object class
*
*/
class Object {
/**
* Array of properties
*
* @var array
*/
protected $_props =array();
/**
* Construct object
*
* @param array $props
*/
public function __construct( $props =array()) {
var_dump( 'constr');
$this->_props =$props;
}
/**
* Magic method override
*
* @param string $key
*/
public function __isset( $key) {
var_dump( 'isset');
return array_key_exists( $key, $this->_props);
}
/**
* Magic method override
*
* @param string $key
* @return mixed/null
*/
public function __get( $key) {
var_dump( 'get');
if( !array_key_exists( $key, $this->_props))
return null;// entry does not exist
// return obtained value
return $this->_props[ $key];
}
/**
* Magic method override
*
* @param string $key
* @param mixed $value
*/
public function __set( $key, $value) {
var_dump( 'set');
$this->_props[ $key] =$value;
}
/**
* Magic method override
*
* @param string $key
*/
public function __unset( $key) {
var_dump( 'unset');
unset( $this->_props[ $key]);
}
/**
* Get associated array
*
* @return array
*/
public function __invoke() {
var_dump( 'invoke');
return $this->_props;
}
/**
* Get object name
*
* @return string
*/
public function __toString() {
return __CLASS__;
}
}
......
mysql_fetch_object( $result, 'Object');
Expected result:
----------------
string(6) "constr"
string(3) "set"
string(3) "set"
string(3) "set"
string(3) "set"
Actual result:
--------------
string(3) "set"
string(3) "set"
string(3) "set"
string(3) "set"
string(6) "constr"
--
Edit bug report at http://bugs.php.net/?id=46105&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46105&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46105&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46105&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46105&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=46105&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46105&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46105&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46105&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46105&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46105&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=46105&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=46105&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46105&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46105&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46105&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46105&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46105&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46105&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46105&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46105&r=mysqlcfg