想实现一个共用的静态数组,大致如下:
  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’求指导修改....能解剖一下相关语法更是感激不尽.....

解决方案 »

  1.   

    我想要在_B中获取到_A中赋予的$Test值,目前结果不能如预期,_B中$Test获取到的是protected  static $Test='Init Value';初始值
      

  2.   

    如果楼主需要打印_A方法中的赋值当然要调用了_A方法后才会改变$Test的值。
      

  3.   

    刚才忽略了楼主的方法居然不是static
    改静态方法:
    public static function _A()
    public static function _B()
      

  4.   

    不知道你在怀疑什么:
    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