怎样在类里面创建DOMDocument对象变量?该如何处理

WBOY
Release: 2016-06-13 13:42:23
Original
717 people have browsed it

怎样在类里面创建DOMDocument对象变量?
class XXX
{
private $_music = new DOMDocument();
}

这样就报错了,
然而不在类里面直接这样的话
$_music = new DOMDocument();

就不报错,请问在类里面要怎样才能创建这样的对象变量?

------解决方案--------------------
语法错误而已,摘自手册 属性中的变量可以初始化,但是初始化的值必须是常数,这里的常数是指php脚本在编译阶段时就为常数,而不是在编译阶段之后在运行阶段运算出的常数。
一般都是放到 __construct()构造函数里赋值,而外面只是声明。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!