simplexml fixes for text children and casting

- fixes text children count and bool cast of empty nodes
Esse commit está contido em:
Daniel Sloof
2013-07-23 14:26:50 -07:00
commit de Sara Golemon
commit 2ac92de922
5 arquivos alterados com 21 adições e 2 exclusões
+6 -2
Ver Arquivo
@@ -524,7 +524,9 @@ Object c_SimpleXMLElement::t_children(CStrRef ns /* = "" */,
elem->m_is_text = m_is_text;
elem->m_free_text = m_free_text;
elem->m_is_children = true;
if (ns.empty()) {
if (m_is_text) {
// text nodes don't have children
} else if (ns.empty()) {
elem->m_children.assignRef(m_children);
} else {
Array props = Array::Create();
@@ -873,7 +875,9 @@ Variant c_SimpleXMLElement::t___set(Variant name, Variant value) {
}
bool c_SimpleXMLElement::o_toBooleanImpl() const noexcept {
return (m_node || getDynProps().size());
return (m_node || getDynProps().size()) &&
(m_node->parent->type != XML_DOCUMENT_NODE ||
m_children.toArray().size());
}
int64_t c_SimpleXMLElement::o_toInt64Impl() const noexcept {
+7
Ver Arquivo
@@ -0,0 +1,7 @@
<?php
$element = new SimpleXMLElement('<root />');
var_dump((bool)$element);
$element = new SimpleXMLElement('<root><child /></root>');
var_dump((bool)$element->child);
@@ -0,0 +1,2 @@
bool(false)
bool(true)
@@ -0,0 +1,4 @@
<?php
$element = simplexml_load_string('<root><hello>world</hello></root>');
var_dump($element->hello->children());
@@ -0,0 +1,2 @@
object(SimpleXMLElement)#4 (0) {
}