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

反正是按照当前类来决定


如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/

 
原文地址:https://www.cnblogs.com/newmiracle/p/14467719.html