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

WBOY
Release: 2016-06-13 13:28:33
Original
1085 people have browsed it

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'
}

}

Copy after login


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;//这样不可以访问,改如何解决呢
}
}


Copy after login


------解决方案--------------------
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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template