Forum Moderators: coopster
I have a problem with static variables in php. How do I access static variables in the super class that are declared in the child?
class SuperClass
{
public static function connect()
{
echo $user;
}
}
class ChildA
{
private static $user = 'John'
}
class ChildB
{
private static $user = 'Smith'
}
This does not seem to work
Thanks for help
here is the corrected code
class SuperClass
{
public static function connect()
{
echo "hello ".self::$user;
}
}class ChildA extends SuperClass
{
protected static $user = 'John';
}
class ChildB extends SuperClass
{
protected static $user = 'Smith';
}
ChildA::connect();
but it gives me this error :
Fatal error: Access to undeclared static property: SuperClass::$user in /home.10/cercleso/www/testingzone/classe.static.php5 on line 7
line 7 being : echo "hello "...
[edited by: RonPK at 9:53 pm (utc) on July 17, 2006]