php self parent 使用

<?php class Foo { public static $my_static = '静1'; public function staticValue() { return self::$my_static; } } class Bar extends Foo { public static $my_static = '静2'; public function fooStatic() { return parent::$my_static; } } print Foo::$my_static . "<br />";//1 $foo = new Foo(); print $foo->staticValue() . "<br />";//2 //print $foo->my_static . "<br />"; // Undefined "Property" my_static print $foo::$my_static . "<br />";//3 $classname = 'Foo'; print $classname::$my_static . "<br />"; // PHP 5.3.0之后可以动态调用3 print Bar::$my_static . "<br />";//4 $bar = new Bar(); print $bar->fooStatic() . "<br />";//5 ?>

 

 

你可能感兴趣的:(php self parent 使用)