I have a class App with static and non static variables.
class App{
protected static $appName = 'dummy';
protected $appIcon = 'icon';
public static function getAppName() {
return self::$appName;
}
}
Then I extend this class like this
class Notepad extends App{
private static $appName = 'notepad';
private $appIcon = 'notepad_icon';
}
I want to get appName without creating an instance of Notepad. I tried Notepad::getAppName() but this returns always dummy.
Any ideas or suggestions???
Thanks in advance!
J!
After Sergey’s post:
I was wandering which is the most OOP way to do something like this, and the most efficient (speed/memory)?
a. declaring variables as puplic
b. creating an instance of an object just to get a few variables
c. rewrite the static function to all the children classes as Sergey suggested
Actually you have a new keyword “static” in php > 5.3.
I changed your example:
This way Notepad::getAppName() will return ‘notepad’;
More info here.