#33274 [Opn]: Class extended from MySQLi mangles members on calling parent method

From: Date: Wed, 08 Jun 2005 15:08:42 +0000
Subject: #33274 [Opn]: Class extended from MySQLi mangles members on calling parent method
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80064@lists.php.net to get a copy of this message
ID: 33274 User updated by: flying dot mushroom at gmail dot com -Reported By: flying dot mushroom at gmail dot cp, +Reported By: flying dot mushroom at gmail dot com Status: Open Bug Type: MySQLi related Operating System: Linux PHP Version: 5.0.3 New Comment: Oops; mistyped my email. Should read flying dot mushroom at gmail dot com Previous Comments: ------------------------------------------------------------------------ [2005-06-08 12:27:00] flying dot mushroom at gmail dot com Description: ------------ A class that extends mysqli, if passing its own members directly to the parent constructor, will have those members mangled after the call. Assigning member values to local variables and then passing those to the parent solves the problem on for the user, but the above behaviour shouldn't happen...? (Replacing the line "parent::__construct($this->p_host, $this->p_uname, $this->p_password);" with "parent::__construct($host, $username, $password);" produces the expected result.) This same problem is reported on the comment by hans at lintoo dot dk on http://www.php.net/manual/en/ref.mysqli.php Reproduce code: --------------- <?php class db_mysql extends mysqli { private $p_host; private $p_uname = ''; private $p_password = ''; public function __construct($host, $username = '', $password = '') { $this->p_host = $host; $this->p_uname = $username; $this->p_password = $password; parent::__construct($this->p_host, $this->p_uname, $this->p_password); } } var_dump(new db_mysql('localhost', 'username', 'password')); ?> Expected result: ---------------- object(db_mysql)#1 (3) { ["p_host:private"]=> string(9) "localhost" ["p_uname:private"]=> string(8) "username" ["p_password:private"]=> string(8) "password" } Actual result: -------------- object(db_mysql)#1 (3) { ["p_host:private"]=> string(9) "localhost" ["p_uname:private"]=> string(8) "username" ["p_password:private"]=> NULL } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33274&edit=1

« previous php.bugs (#80064) next »