标签:cti 的区别 class public elf his 区别 function this
class Foo
{
public static $str = 'This is foo';
public static function show()
{
echo __METHOD__ . PHP_EOL;
echo static::$str;
}
}
class Boo extends Foo
{
public static $str = 'This is boo';
}
Boo::show();
# 输出结果
# Foo::show
# This is boo
使用 static
调用的是当前类的变量
class Foo
{
public static $str = 'This is foo';
public static function show()
{
echo __METHOD__ . PHP_EOL;
echo self::$str;
}
}
class Boo extends Foo
{
public static $str = 'This is boo';
}
Boo::show();
# 输出结果
# Foo::show
# This is foo
使用 self
调用的是最高级的父类的变量
标签:cti 的区别 class public elf his 区别 function this
原文地址:https://www.cnblogs.com/pandaLIU/p/12460671.html