标签:
<?php class BaseClass{ public function test(){ echo "BaseClass::test called\n"; } public function test1(){ echo "BaseClass::test1 called\n"; } } class ChildClass extends BaseClass{ const CONST_VALUE = "A constant value\n"; private static $sValue = "static value\n"; public function test(){ echo "ChildClass::test called\n"; parent::test(); //使用parent关键字可以访问父类中被子类重写的方法 self::called(); echo self::CONST_VALUE; echo self::$sValue; //使用self关键字可以访问自身的成员方法和常量成员 } public function called(){ echo "ChildClass::called() called\n"; } } $obj = new ChildClass(); $obj->test();
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qsyzb/article/details/47999109