我需要知道什么类型调用静态方法,而不发送参数
class foo
{
public static function test($clase)
{
echo "Class invoke:" . FUNCTION();
}
}
class A { public function x { foo::test(); } }
class B { public function y { foo::test(); } }
class C { public function z { foo::test(); } }
答案 0 :(得分:0)
如果您将所有类扩展为foo
,则可以使用后期静态绑定和get_called_class()
(PHP> = 5.3),如下所示:
class foo
{
public static function test($clase)
{
echo "Class invoke:" . get_called_class();
}
}
class A extends foo { public function x() { self::test(''); } }
class B extends foo { public function y() { self::test(''); } }
class C extends foo { public function z() { self::test(''); } }
使用这些对象:
$a = new A; $a->x();
$b = new B; $b->y();
$c = new C; $c->z();
Class invoke:A
Class invoke:B
Class invoke:C