可能重複:
Why is my constructor still called even if the class and constructor case are different?我在PHP中發現了錯誤還是錯過了一些東西?
<?php
abstract class foo {
function foof() {
echo "Hello, I'm foo :)";
}
}
class foo2 extends foo {
function foo2f() {
$this->foof();
}
}
class foo3 extends foo2 {
function foo3f() {
$this->foo2f();
}
}
$x = new foo3;
$x->foo3f();
?>
這段代碼輸出 「你好,我是富:)」(如預期),但是當我改變的代碼是這樣的: http://pastebin.com/wNeyikpq
<?php
abstract class foo {
function fooing() {
echo "Hello, I'm foo :)";
}
}
class foo2 extends foo {
function foo2() {
$this->fooing();
}
}
class foo3 extends foo2 {
function foo3() {
$this->foo2();
}
}
$x = new foo3;
$x->foo3();
?>
PHP打印:
你好,我是富:)你好,我是富:)
爲什麼?這是一個錯誤嗎?
我把第二個代碼上,由於引擎收錄到stackoverflow錯誤(哈哈) - http://cl.ly/3J352B14073S15282O2s – kiler129
這不是PHP中的錯誤,這不是StackOverflow中的錯誤。 –
總的來說,如果你的問題假設(即使你只是簡單地提到它),你會在這裏畫人的憤怒,說你正在使用的語言有一個錯誤,而不是你寫的代碼。 – jwiscarson