Aquí hay un ejemplo de lo que ocurre cuando se llama a un método de una clase una manera incorrecta. Verá algunas advertencias cuando ejecute este código pero funcionará e imprimirá: "Estoy A: imprimiendo propiedad B". (Ejecutado en php5.6)
class A {
public function aMethod() {
echo "I'm A: ";
echo "printing " . $this->property;
}
}
class B {
public $property = "B property";
public function bMethod() {
A::aMethod();
}
}
$b = new B();
$b->bMethod();
Se costuras que la variable $ this, utilizada en un método que se llama como un método estático, apunta a la instancia de la clase "llama". En el ejemplo anterior hay $ this-> bienes utilizados en la clase A que apunta a una propiedad de la B.
EDIT:
The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object). PHP > The Basics
cierto, estaba a punto de publicar esta respuesta. –
También debe recordar que el método getsomthin() también debe ser estático: no puede llamar a no static dentro de un método estático. – thorinkor
@Sarfraz, ¿no debería ser 'static ::' en lugar de 'self ::'? – Pacerier