时间:2021-07-01 10:21:17 帮助过:15人阅读
* Foo * cB * Tango * cC * Foo * cD * * What the hell?! :) */ ?>
class cA
{
/**
* Test property for using direct default value
* 使用直接默认值测试属性
*/
protected static $item = 'Foo';
/**
* Test property for using indirect default value
* 使用间接默认值测试属性
*/
protected static $other = 'cA';
public static function method()
{
print __METHOD__ . ' ' . __CLASS__ . '::$item=' . self::$item."\r\n";
print __METHOD__ . ' ' . __CLASS__ . '::$otfer=' . self::$other."\r\n";
}
public static function setOther($val)
{
self::$other = $val; // Set a value in this scope.
}
}
class cB extends cA
{
/**
* Test property with redefined default value
* 重新定义了默认值测试属性
*/
protected static $item = 'Bar';
public static function setOther($val)
{
self::$other = $val;
}
}
class cC extends cA
{
/**
* Test property with redefined default value
* 重新定义了默认值测试属性
*/
protected static $item = 'Tango';
public static function method()
{
print __METHOD__ . ' ' . __CLASS__ . '::$item=' . self::$item."\r\n";
print __METHOD__ . ' ' . __CLASS__ . '::$otfer=' . self::$other."\r\n";
}
/**
* Now we drop redeclaring the setOther() method, use cA with 'self::' just for fun.
*/
}
class cD extends cA
{
/**
* Test property with redefined default value
* 重新定义了默认值测试属性
*/
protected static $item = 'Foxtrot';
/**
* Now we drop redeclaring all methods to complete this issue.
* 现在,我们放弃重新声明的所有方法来完成这个问题
*/
}
cB::setOther('cB'); // It's cB::method()!
cB::method(); // It's cA::method()!
cC::setOther('cC'); // It's cA::method()!
cC::method(); // It's cC::method()!
cD::setOther('cD'); // It's cA::method()!
cD::method(); // It's cA::method()!