我正在努力解决这个问题好几个小时......我已经成功缩小了Symfony3的问题,并意识到它只与PHP有关。
当我在2个不同的环境(VM内部/外部)执行以下代码时,我得到2个不同的输出。
$dom = new \DOMDocument();
print_r($dom);
$dom->loadXML('<root><node/></root>');
print_r($dom->documentElement);
VM之外:
DOMDocument Object (
[nodeName] => #document
[nodeValue] =>
[nodeType] => 9
[parentNode] =>
[childNodes] => (object value omitted)
[firstChild] =>
[lastChild] =>
[previousSibling] =>
[attributes] =>
[ownerDocument] =>
[namespaceURI] =>
[prefix] =>
[localName] =>
[baseURI] =>
[textContent] =>
)
Notice: Undefined property: DOMDocument::$documentElement in /var/www/lab/xml/index.php on line 9
VM内部:
DOMDocument Object (
[doctype] =>
[implementation] => (object value omitted)
[documentElement] =>
[actualEncoding] =>
[encoding] =>
[xmlEncoding] =>
[standalone] => 1
[xmlStandalone] => 1
[version] => 1.0
[xmlVersion] => 1.0
[strictErrorChecking] => 1
[documentURI] =>
[config] =>
[formatOutput] =>
[validateOnParse] =>
[resolveExternals] =>
[preserveWhiteSpace] => 1
[recover] =>
[substituteEntities] =>
[nodeName] => #document
[nodeValue] =>
[nodeType] => 9
[parentNode] =>
[childNodes] => (object value omitted)
[firstChild] =>
[lastChild] =>
[previousSibling] =>
[attributes] =>
[ownerDocument] =>
[namespaceURI] =>
[prefix] =>
[localName] =>
[baseURI] =>
[textContent] =>
)
DOMElement Object (
[tagName] => root
[schemaTypeInfo] =>
[nodeName] => root
[nodeValue] =>
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => root
[baseURI] => /var/www/xml/
[textContent] =>
)
有什么想法吗?
编辑1: 我在两个环境(来自phpinfo)上都有相同的配置:
XML:
XML支持:活跃的
XML命名空间支持:活动
libxml2:版本2.9.3
的libxml:
libXML支持:活跃的
libXML编译版本:2.9.3
libXML加载版本:20903
libXML流:启用
的SimpleXML:
修订:$ Id:b8b5c37931a53e50a937c0aef2a26d351e173215 $
架构支持:已启用