mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
Fixed counting children of SimpleXMLElement object
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user