php 面向对象相关
构造函数的问题:
第一种情况:子类没有定义构造函数时,默认继承。
第二种情况:子类定义了构造函数,则不会被继承。
对于4.x,如果父类恰好定义了子类的同名函数,则会被当做子类的构造函数:
class A
{
function A()
{
echo "I am the constructor of A.<br>\n";
}
function B()
{
echo "I am a regular function named B in class A.<br>\n";
echo "I am not a constructor in A.<br>\n";
}
}
class B extends A
{
function C()
{
echo "I am a regular function.<br>\n";
}
}
//php4 will call B()
$b = new B;
上面的代码在php5中则会调用A而不会调用B()

