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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:26:40
Original
899 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:
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
Latest Issues
php - laravel public related issues
From 1970-01-01 08:00:00
0
0
0
Don’t you need to bring public?
From 1970-01-01 08:00:00
0
0
0
public method library
From 1970-01-01 08:00:00
0
0
0
How does laravel get the public path?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template