Subclass uses the parent class variable classA {var $ authKey = '000000';} classBextendsA {& nbsp ;__ construct () {& nbsp; echoparent: authKey ;}} the error "Undefinedclassconstant 'authkey'" is returned. the error message indicates that the undefined subclass uses the parent class variable.
Class {
Var $ authKey = '20140901 ';
}
Class B extends {
_ Construct (){
Echo parent: authKey;
}
}
Error: Undefined class constant 'authkey'
------ Solution --------------------
The error message indicates an undefined constant. You are missing $
But $ authKey is not a static variable, so you cannot call it so statically.
Correct practice
PHP code
Class A {// use var to declare the variable public $ authKey = '000000 ';} class B extends A {// B will have all non-private members of A public function _ construct () {echo $ this-> authKey ;}}
------ Solution --------------------
Var is a version earlier than php4 and is omitted later.
------ Solution --------------------
Var should be taken as appropriate! Some earlier versions support
------ Solution --------------------
Var is used in php 4.x, and 5 + for backward compatibility ,,
The newly written program can basically give up this writing.
Your code can also be used like this
PHP code
class A {const authKey='1111';}class B extends A{ public function __construct(){ echo parent::authKey;}}new B;