PHP static::的用法

PHP  static::的用法

<?php

class a{

static protected $test="class a";

public function static_test(){

echo static::$test; // Results class b
echo self::$test; // Results class a

}

}
class b extends a{

// static protected $test="class b";

}
$obj = new b();
$obj->static_test();

 

这个输出是 class aclass a

// static protected $test="class b"; 如果加上就是重写了这个属性
那就是 class aclass b

反正是按照当前类来决定

 

posted @ 2021-03-02 10:39  newmiracle宇宙  阅读(445)  评论(0编辑  收藏  举报