Php static variable initialization. For example: classA {public $ f1xxxx; staticpublic $ f2100;} to assign a variable to an object, you can only initialize the variable in the constructor. for example: classA {private $ chi, for example:
Class {
Public $ f1 = 'xxxx ';
Static public $ f2= 100;
}
If you want to assign a variable to an object, you can only initialize the variable in the constructor. for example:
Class {
Private $ child;
Public function _ construct (){
$ This-> child = new B ();
}
}
However, php does not have anything similar to the static constructor/static block in java, so there is no proper time to initialize it.
There are still solutions for common members, such:
Class {
Static public $ child;
}
A: $ child = new B ();
There seems to be no clean method for private members. you can only do this:
Class {
Static private $ child;
Static public initialize (){
Self: $ child = new B ();
}
}
A: initialize ();
Keep class A {public $ f1 = 'xxxx'; static public $ f2 = 100;} to assign A variable to an object, you can only initialize the variable in the constructor. for example: class A {private $ chi...