Home >Backend Development >PHP Tutorial >php类中的静态方法不能继承别的类中的public修饰的属性该怎么解决
php类中的静态方法不能继承别的类中的public修饰的属性该如何解决
php类中的静态方法不能继承别的类中的public修饰的属性该如何解决?如par.class.php和st.class.php代码如下:
par.class.php代码:
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class par{public $aa;public function __contruct(){$this->aa='123456'}}
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class st extends par{static function bb{echo $this->aa;//这样不可以访问,改如何解决呢}}
class par{ public $aa; public function __construct(){ $this->aa = '123456'; }}class st extends par { static function bb($o) { echo $o->aa; }}$p = new par; // new st 也是一样st::bb($p);<div class="clear"> </div>