想实现一个共用的静态数组,大致如下:
class Test extends xxxxx
{
protected static $Test='Init Value'; //这个静态函数需要只能本类中访问
public function _A()
{
self::$Test='Write the Value';
echo 'Test:'.self::$Test;
}
public function _B()
{
echo 'Print:'.self::$Test; //$Test能打印出_A方法中的赋值Write the Value
}
}
目前结果不能如预期,而是_B中$Test打印出了,初始值‘Init Value’求指导修改....能解剖一下相关语法更是感激不尽.....
class Test extends xxxxx
{
protected static $Test='Init Value'; //这个静态函数需要只能本类中访问
public function _A()
{
self::$Test='Write the Value';
echo 'Test:'.self::$Test;
}
public function _B()
{
echo 'Print:'.self::$Test; //$Test能打印出_A方法中的赋值Write the Value
}
}
目前结果不能如预期,而是_B中$Test打印出了,初始值‘Init Value’求指导修改....能解剖一下相关语法更是感激不尽.....
改静态方法:
public static function _A()
public static function _B()
Test::_A();
Test::_B();
在 error_reporting(E_ALL ^ E_NOTICE); 条件下,将输出
Test:Write the ValuePrint:Write the Value在 error_reporting(E_ALL ^ E_NOTICE | E_STRICT); 条件下,将得到
Strict standards: Non-static method Test::_A() should not be called statically in ...总之不会出现 Init Value