Jump to content

Super class static properties


shadowayex

Recommended Posts

This may not be quite possible, but here's what I want.I have a super class that has a static property it. I want to set a different value for that property in each sub class I make, but I want he super class to still be able to use it.Example:

class Foo{	protected static a;	public static getA()	{		return self::a;	}}class BarOne extends Foo{	// Set a to "One" in here somewhere}class BarTwo extends Foo{	// Set a to "Two" in here somewhere}BarOne::getA(); // Should return "One"BarTwo::getA(); // Should return "Two"

I hope that explains it well enough. If not, let me know.Is that possible?

Link to comment
Share on other sites

If i am not missunderstanding the question it is not possible When you inherit a static property it also been inherited in child class. static properties are class based not instance based. So the value of static properties remain same across different instance of a class.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...