class A {
var $authKey='1111';}class B extends A{
 __construct(){
   echo parent::authKey;
}
}
报错Undefined class constant 'authKey'

解决方案 »

  1.   

    错误信息的意思是未定义的常量。你少了个$
    但$authKey不是静态变量,所以你不能这么静态调用
    正确的做法
    class A {
       // 不建议类中用var来声明变量
       public $authKey='1111';
    }class B extends A{
       // B将拥有A的所有非private成员
       public function __construct(){
          echo $this->authKey;
       }
    }
      

  2.   

    楼主利用var去定义一个变量,第一次看到。
      

  3.   

    http://hi.baidu.com/uaoou/blog/item/161e628bcd30e515c8fc7a53.html
      

  4.   

    var 是在php4以前的版本,后来就省略了。
      

  5.   

    var最好还是视情况带上!有些低版本支持
      

  6.   

    var 是php 4.X中的,,,5+里使用是为了向下兼容,,新写的程序,基本可以放弃这种写法了你的代码也可以这样用class A {
    const authKey='1111';}class B extends A{
     public function __construct(){
      echo parent::authKey;
    }
    }new B;