天天看點

php 執行個體調用靜态方法,php – 确定靜态方法是靜态調用還是作為執行個體方法調用

PHP中,可以調用靜态方法,就好像它們是執行個體方法一樣:

class A {

public static function b() {

echo "foo";

}

}

$a = new A;

A::b(); //foo

$a->b(); //foo

有沒有辦法确定b()内部是否靜态調用該方法?

我嘗試了isset($this),但在兩種情況下都傳回false,而debug_backtrace()似乎表明這兩個調用實際上都是靜态調用

array(1) {

[0]=>

array(6) {

["file"]=>

string(57) "test.php"

["line"]=>

int(23)

["function"]=>

string(1) "b"

["class"]=>

string(1) "A"

["type"]=>

string(2) "::"

["args"]=>

array(0) {

}

}

}

Foo

array(1) {

[0]=>

array(6) {

["file"]=>

string(57) "test.php"

["line"]=>

int(24)

["function"]=>

string(1) "b"

["class"]=>

string(1) "A"

["type"]=>

string(2) "::"

["args"]=>

array(0) {

}

}

}