分两部分回答。
首先,关于名义上的问题:非静态调用静态方法非常好;@SamDark 的评论是正确的。它不会产生警告,也不会导致任何小猫谋杀。尝试一下:
<?php
class test {
public static function staticwarnings(){
echo "YOU ARE (statically) WARNED!\n";
}
}
error_reporting(E_ALL);
$test = new test();
echo "\n\ncalling static non-statically\n";
$test->staticwarnings();
如果您$this
在该静态方法中有一个实例引用 , ,那么您将收到一个致命错误。但不管你怎么称呼它都是真的。
再一次,没有警告,也没有任何小猫被杀。
答案的第二部分:
Calling an overridden parent function from an overriding child class requires something called "scope resolution". What the OP is doing in their method is NOT calling a static method. (Or at least, it doesn't have to be; we can't see the parent implementation). The point is, using the parent keyword is not a static call. Using the ::
operator on an explicit parent class name is also not a static call, if it is used from an extending class.
Why is that documentation link so strangely named? It's literally Hebrew. If you've ever run into an error related to it, you might have observed the delightfully-named parser error code T_PAAMAYIM_NEKUDOTAYIM
.