Using global variables in mysqli-extended class
| From: | Guus der Kinderen | Date: | Mon, 09 Aug 2004 17:32:08 +0000 |
| Subject: | Using global variables in mysqli-extended class | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-35630@lists.php.net to get a copy of this message | ||
Could someone confirm or deny this? 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 below), you would expect an output like "xconstructorytest" however, I'm getting "xy" (the private variable $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 variable.
Can anyone confirm this, or explain this behaviour to me?
Regards,
Guus der Kinderen
// ************ php 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();