php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33274 Class extended from MySQLi mangles members on calling parent method
Submitted: 2005-06-08 12:27 UTC Modified: 2005-06-09 16:17 UTC
From: flying dot mushroom at gmail dot com Assigned:
Status: Closed Package: MySQLi related
PHP Version: 5.0.3 OS: Linux
Private report: No CVE-ID: None
 [2005-06-08 12:27 UTC] 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
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-08 18:02 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-06-09 12:51 UTC] flying dot mushroom at gmail dot com
Yep; the CVS version (200506090830) fixes it, producing the expected result.
 [2005-06-09 16:17 UTC] flying dot mushroom at gmail dot com
Fixed in CVS
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 07:01:34 2024 UTC