DOMNodeList doesn't implement Traversable interface in PHPv5.3.2-1ubuntu4.14

Posted on 14th February, 2012 | Tagged:

So I have just spent about 4 hours scratching my head, then cursing at my computer as for some inexplicable reason TWIG would not iterate over my DONNodeList.

Finally I found the problem, an internal twig function ensure_tranersable checks if the given element (to be used in a loop) is traversable by seeing either if it is an Array or if it implements the Traversable interface.

DOMNodeList implements the Traversable interface, but apparently it doesn't implement it in the version of PHP we use on our server ..

My machine:

PHP Version: 5.3.9-1
DOMNodeList interfaces: 
Array
(
    [Traversable] => ReflectionClass Object
        (
            [name] => Traversable
        )

)

The server:

PHP Version: 5.3.2-1ubuntu4.14
DOMNodeList interfaces: 
Array
(
)

and the corresponding code that this breaks in Twig:

/* used internally */
function twig_ensure_traversable($seq)
{
    if (is_array($seq) || (is_object($seq) && $seq instanceof Traversable)) {  
        return $seq;
    } else {
        return array();
    }
}

Solution?? Upgrade PHP? Patch Twig? I dont know.

Comments

Be the first to leave a comment.

Post new comment


type "i hate spam" in UPPER CASE

Tags

10 Latest Items