Your code here
class B extends A
{
A::setX();
}
is a little off. You didn't put your call inside of a method.
class B extends A
{
public static function doSomething() {
A::setX();
}
}
This isn't actually doing anything by means of the parent/child relationship. In fact, after you define class A, the call to A::setX() can happen anywhere since it's public and static. This code is just as valid:
class A
{
function isXSet()
{
return X;
}
public static function setX()
{
define('X', 1);
}
}
class B { // No extending!
function isXSet() {
return A::isXSet();
}
}
What you're more likely looking for is parent instead:
class A
{
public function isXSet()
{
return X;
}
protected static function setX()
{
define('X', 1);
}
}
class B extends A
{
public static function doSomething() {
parent::setX();
var_dump( parent::isXSet() ); // int(1)
}
}
A big plus here is that extending classes can access protected methods and properties from the parent class. This means you could keep everyone else from being able to call A::setX() unless the callee was an instance of or child of A.
A::setX();is just 'flying around' (it's not inside a method)...setX()onB, it will call A's method because you extended it (without overriding)