一般调用非静态方法,我们一般都是先创建一个类的实例,然后通过实例来调用方法。
但我今天发现这样也可以正常运行,所以就有点糊涂了,请大家来看看,这是为何?
<?php
class ParentObject{
function baseobject(){
echo "this is from parent!\n" ;
}
}
class subObject extends PaentObject{
function extendmethod(){
echo "this is from extension!\n";
self::baseobject();
}
}
subObject::extendmethod();
?>
但我今天发现这样也可以正常运行,所以就有点糊涂了,请大家来看看,这是为何?
<?php
class ParentObject{
function baseobject(){
echo "this is from parent!\n" ;
}
}
class subObject extends PaentObject{
function extendmethod(){
echo "this is from extension!\n";
self::baseobject();
}
}
subObject::extendmethod();
?>
不过这只是继承了php4的写法
对于php5.3及以后由于做了更严格的限定,这样写的话会有一个 Strict standards 警告