Fixed counting children of SimpleXMLElement object

This commit is contained in:
webimpress
2018-03-14 10:16:52 +00:00
parent 981c4d8ca0
commit 4a23bdc345
2 changed files with 11 additions and 0 deletions
+8
View File
@@ -1263,6 +1263,10 @@ if (function_exists('mb_get_info')) {
return mb_strlen($thing, $env->getCharset());
}
if ($thing instanceof \SimpleXMLElement) {
return count($thing);
}
if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
return mb_strlen((string) $thing, $env->getCharset());
}
@@ -1366,6 +1370,10 @@ else {
return strlen($thing);
}
if ($thing instanceof \SimpleXMLElement) {
return count($thing);
}
if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
return strlen((string) $thing);
}
@@ -10,6 +10,7 @@
{{ null|length }}
{{ magic|length }}
{{ non_countable|length }}
{{ simple_xml_element|length }}
--DATA--
return array(
'array' => array(1, 4),
@@ -21,6 +22,7 @@ return array(
'null' => null,
'magic' => new MagicCallStub(), /* used to assert we do *not* call __call */
'non_countable' => new \StdClass(),
'simple_xml_element' => new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><doc><elem/><elem/></doc>'),
);
--EXPECT--
2
@@ -32,3 +34,4 @@ return array(
0
1
1
2