get_called_class()은 항상 실제로 호출하는 클래스를 반환합니다. A2 ::이므로 A2입니다.
내 사이트에는 LSB 싱글 톤 추상 클래스과 함께 자습서가 있습니다. 나는 항상 좀비 자경단이 와서 보지 않고 링크를 제거하기 때문에 여기에 링크하지 않습니다. 하지만 내 설명에 있습니다.
LSB의 catch는 A의 메소드가 A의 메소드를 호출 할 수있는 B의 메소드를 호출 할 수 있다는 것입니다. 이 예를 참조하십시오
header('Content-Type: text/plain'); // Pretty text output
// LSB Parent
class A {
// NOLSB: Will call Current Class method
static public function TriggerSelf() {
self::OverrideMe();
}
// LSB: Will call Inheriting Class method (or Current if none Inherits)
static public function TriggerStatic() {
static::OverrideMe();
}
// Method to Override
static public function OverrideMe() {
echo 'A here', PHP_EOL;
}
}
// LSB Child
class B extends A {
// Override by LSB
static public function OverrideMe() {
echo 'B here', PHP_EOL;
}
}
A::TriggerSelf(); // <- NO LSB
A::TriggerStatic(); // <- LSB (but not inheritance)
B::TriggerSelf(); // <- NO LSB
B::TriggerStatic(); // <- LSB (with inheritance, so it works)
이 B : TriggerStatic는()는 A가 B : TriggerSelf (동안 B의 메소드를 호출 할 수 있습니다 방법 참조) 방법 호출. LSB입니다. 부모 클래스 정적 메서드는 자식 클래스 정적 메서드를 호출 할 수 있습니다. 꽤 정적 인 초록입니다 :)
예제를 살펴보면 이해가됩니다.