How to create a DOMDocument object variable in the class? What should I do?
Source: Internet
Author: User
How to create a DOMDocument object variable in the class? & Lt ;? PhpclassXXX {private $ _ music = newDOMDocument ();} in this way, an error is reported. if this is not the case in the class, $ _ music = newDOMDocument (); how to create a 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.