How to create a DOMDocument object variable in the class? & Lt ;? PhpclassXXX {private $ _ musicnewDOMDocument ();} in this way, an error is reported, but $ _ musicnewDOMDocument () is not directly returned in this case in the class, how can I create such an object variable in a class? ------ Solution --------------- How to create the DOMDocument object variable in the class?
Class XXX
{
Private $ _ music = new DOMDocument ();
}
In this way, an error is reported,
However, this is not the case in the class.
$ _ Music = new DOMDocument ();
No error is reported. how can I create such an object variable in the class?
------ Solution --------------------
A syntax error occurs. variables from the manual attributes can be initialized, but the initialization value must be a constant. the constant here means that the php script is a constant during compilation, instead of the constant calculated in the running phase after the compilation phase.
Generally, values are assigned to the _ construct () constructor, while values are declared outside the construct () constructor.