考虑一下:
class Player {
public static function echoSomthing(){
echo "A";
}
}
和
class ModifiedPlayer extends Player {
public static function echoSomthing(){
echo "B";
}
}
好的,所以我覆盖了我的静态echoSomthing函数,但“A”仍然得到回应。我做错了什么?
答案 0 :(得分:0)
正如Sahil Gulati和pAsh以及其他
的评论中所述我们需要使用范围分辨率运算符::
请运行以下代码,然后输出B
<?php
class Player {
public static function echoSomthing() {
echo "A";
}
}
class ModifiedPlayer extends Player {
public static function echoSomthing() {
echo "B";
}
}
ModifiedPlayer::echoSomthing();
答案 1 :(得分:0)
class Player {
public static function echoSomthing(){
echo "A";
}
}
class ModifiedPlayer extends Player {
public static function echoSomthing(){
echo "B";
}
}
$ob = new ModifiedPlayer();
$ob->echoSomthing(); // B displayed here