Rumah > pembangunan bahagian belakang > tutorial php > php类中的静态方法不能继承别的类中的public修饰的属性该怎么解决

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-06-13 13:28:33
asal
1139 orang telah melayarinya

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

}

Salin selepas log masuk


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


Salin selepas log masuk


------解决方案--------------------
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>
Salin selepas log masuk
Label berkaitan:
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan