计算根节点内的元素

I'm pretty new to php, but I've been googling around and got to write this code:

<?php

$xml = simplexml_load_file("playlist.xml");
echo 'Count: '.$xml->count();

?>

should print Count: 5 for the next file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<playlist>
<vid src="video/P_ANIMACION.mp4"/>
<vid src="video/120414MIAMGIOQUIJOTE.mp4"/>
<vid src="video/120314ENSEMBLEDIDER.mp4"/>
<vid src="video/120418ENSEMBLEPRAETERITUM.mp4"/>
<vid src="video/P_AGLOBAL CAJA.mp4"/>
</playlist>

However I get "Fatal error: Call to undefined method SimpleXMLElement::count()", which doesn't look very logical since count does exist for SimpleXMLElement (see link). Anyone knows why does this happen?

As I added in the comment, ->count() was first added to SimpleXMLElement in PHP 5.3. If you're on an earlier version than that, you'll have to use:

count($xml->children());

instead. This gives the same answer on PHP 5.3 at least.