【发布时间】:2011-12-02 22:02:24
【问题描述】:
可能重复:
Why is my constructor still called even if the class and constructor case are different?
<?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();
?>
此代码输出“你好,我是 foo :)”(如预期的那样)但是当我将代码更改为如下内容时: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 打印:
你好,我是 foo :)你好,我是 foo :)
为什么?是bug吗?
【问题讨论】:
-
由于 stackoverflow 错误,我在 pastebin 上放了第二个代码 (lol) - cl.ly/3J352B14073S15282O2s
-
这不是 PHP 中的错误,也不是 StackOverflow 中的错误。
-
一般来说,如果您的问题假设(即使您只是顺便提及)您使用的语言存在错误,而不是在您编写的代码中。
标签: php constructor php4