ID: 46105
Updated by: [EMAIL PROTECTED]
Reported By: ninzya at inbox dot lv
-Status: Open
+Status: Assigned
Bug Type: MySQL related
Operating System: Windows XP
PHP Version: 5.3.0alpha2
-Assigned To:
+Assigned To: mysql
Previous Comments:
------------------------------------------------------------------------
[2008-09-17 12:35:52] ninzya at inbox dot lv
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 this bug report at http://bugs.php.net/?id=46105&edit=1