<?php
class a
{
static protected $test = "class a";
public function static_test()
{
/**
* static::$test 如果有继承的话 默认调用子类 ,否则调用的是自身
*
* self::$test 如果有继承的话,默认调用父类,否则调用自身
*/
var_dump(static::$test);
var_dump(self::$test);
}
}
class b extends a
{
static protected $test = "class b";
}
$obj = new b();
$obj->static_test();
/**
* 输出结果
*
*/
//string(7) "class b"
//string(7) "class a"
class c
{
static protected $test = "class c";
}
class d extends c
{
static protected $test = "class d";
public function static_test()
{
/**
* static::$test 如果有继承的话 默认调用子类 ,否则调用的是自身
*
* self::$test 如果有继承的话,默认调用父类,否则调用自身
*/
var_dump(static::$test);
var_dump(self::$test);
}
}
$objs = new d();
$objs->static_test();
/**
* 输出结果
*
*/
//string(7) "class d"
//string(7) "class d"
php 静态类的之static::class 和self::class的区别