According to PHP manual, those two parameters have been added in PHP version 5.2. The official PHP 5 changelog does not note these changes explicitly but the PHP 5.2 update readme has these.
Then looking into the 5.2 source for the constructor (in lxr) it shows that this is related to the iterator:
sxe->iter.nsprefix = ns_len ? xmlStrdup((xmlChar *)ns) : NULL;
sxe->iter.isprefix = isprefix;
So I assume those two specify the XML Namespace that SimpleXMLElement
will iterate over by default. A little test can verify this:
$xml = new SimpleXMLElement(
'<root><a/><b/><c/></root>'
);
var_dump(count(iterator_to_array($xml))); #int(3)
By default, the iterator has three elements here: a, b and c. Now setting the parameters specifying the iteration to be over a different XML-Namespace than the default one changes this:
$xml = new SimpleXMLElement(
'<root><a/><b/><c/></root>', 0, FALSE, "ns:1"
);
var_dump(count(iterator_to_array($xml))); #int(0)
The iteration now has zero elements because the root-element does not have any child-elements in the namespace of URI ns:1
.
Changing the namespace of the root element to ns:1
will again reveal three elements because now those three child-elements are in that namespace, they inherit it from their parent:
$xml = new SimpleXMLElement(
'<root xmlns="ns:1"><a/><b/><c/></root>', 0, FALSE, "ns:1"
);
var_dump(count(iterator_to_array($xml))); #int(3)
Same as if the children itself are in the namespace specified by that parameter pair and via a prefix on these elements:
$xml = new SimpleXMLElement(
'<root xmlns:n="ns:1"><n:a/><n:b/><n:c/></root>', 0, FALSE, "ns:1"
);
var_dump(count(iterator_to_array($xml))); #int(3)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…