If a class inherits a method from a parent function and you call the parent
method from the inherited class you cannot refer to variables referred in
the inherited class. Is there a language construct to refer to the calling
class inside a method?
The example will explain it better:
<?php
class db
{
static function query()
{
echo self::$connString;
}
}
class dbOne extends db
{
protected $connString = 'host=localhost blablla';
}
echo dbOne::query();
?>
And it generates:
Fatal error: Access to undeclared static property: db::$connString in
/var/dev/jalonso.gea/app/db_new.php on line 6
I know this has been brought before but I don't remember if there is any
workaround besides redefining the method in the inherited class and passing
the parent class it's name, which is what I am doing currently:
<?php
class db
{
static function query($connString)
{
echo $connString;
}
}
class dbOne extends db
{
protected $connString = 'host=localhost blablla';
static function query()
{
return parent::query(self::$connString);
}
}
echo dbOne::query();
?>
Regards,
Juan Alonso