php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29596 Setting or getting declared members won't work when extending mysqli
Submitted: 2004-08-10 09:56 UTC Modified: 2004-08-11 06:37 UTC
From: kinder at wxs dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.0 OS: Windows XP
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kinder at wxs dot nl
New email:
PHP Version: OS:

 

 [2004-08-10 09:56 UTC] kinder at wxs dot nl
Description:
------------
I've posted this problem to the php.db mailinglist, as well as asked in three different php-related irc-channels, in which no-one could explain this behaviour. Although I haven't been able to reproduce this problem on another machine (none available), I suspect it to be a bug.

-----

I'm running php5.0.0 with mysqli extention as a Apache2 module on a Windows XP box. I've tested the database by querying it with mysqli (procedural) and results are coming back just fine. This makes me believe that the mysqli-extention is working properly.

Running this code (see 'reproduce code'), you would expect an output like "xconstructorytest" however, I'm getting "xy" (the private member $somevar isn't set and/or read). No reported errors or warnings.

Changing the line that says

 class database_foobar extends mysqli
to
 class database_foobar

gets me the expected result of "xconstructorytest". Somehow, making the class an extention of mysqli, seems to interfere with calling the $somevar member. 


Reproduce code:
---------------
error_reporting(E_ALL);

class database_foobar extends mysqli
{

    private $somevar;

    function database_foobar()
    {
        $this->somevar = "constructor";
        echo "x";
        echo $this->somevar;
    }

    function test()
    {
        $this->somevar = "test";
        echo "y";
        echo $this->somevar;
    }
}

$foo = new database_foobar();
$foo->test(); 

Expected result:
----------------
xconstructorytest

Actual result:
--------------
xy

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-11 06:37 UTC] georg@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You have to override mysqli's default constructor with 
function __construct inside your extended class. 
 
See http://www.php.net/manual/en/language.oop5.decon.php 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 12:01:31 2025 UTC