Home >Backend Development >PHP Tutorial >php类中的静态方法不能继承别的类中的public修饰的属性该怎么解决

php类中的静态方法不能继承别的类中的public修饰的属性该怎么解决

WBOY
WBOYOriginal
2016-06-13 10:26:40850browse

php类中的静态方法不能继承别的类中的public修饰的属性该如何解决
php类中的静态方法不能继承别的类中的public修饰的属性该如何解决?如par.class.php和st.class.php代码如下:

par.class.php代码:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class par{public $aa;public function __contruct(){$this->aa='123456'}}


st.class.php代码:
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class st extends par{static function bb{echo $this->aa;//这样不可以访问,改如何解决呢}}


------解决方案--------------------
PHP code
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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn