John Davidson

php - Are SimpleXMLElement and SimpleXMLElement::children() the same thing?

0 comments
Message:


Consider the following code:


<?php
$foo = new SimpleXmlElement(
'<foo>
<bar>
<baz id="b1"/>
<baz id="b2"/>
<baz id="b3"/>
</bar>
</foo>
');
echo "<pre>";print_r($foo);echo "</pre><br/>";
echo "<pre>";print_r($foo->children());echo "</pre><br/>";
echo "foo===foo->children():".($foo===$foo->children()?"true":"false")."<br/>";//false
echo "foo==foo->children():".($foo==$foo->children()?"true":"false");//true

print_r shows the same content for foo and foo->children(). $foo==$foo->children() is true but $foo===$foo->children() is false. What the heck is $foo->children()?


The official document has a note that may be related to this question, but I cannot understand exactly its meaning.



Note: SimpleXML has made a rule of adding iterative properties to most
methods. They cannot be viewed using var_dump() or anything else which
can examine objects.




My Answer:
No, SimpleXMLElement and SimpleXMLElement::children() are not the same thing.

SimpleXMLElement is a class in PHP that represents an XML element. It is used to manipulate XML data.

SimpleXMLElement::children() is a method of the SimpleXMLElement class that returns a SimpleXMLElement object representing the children of the current XML element.

In the code snippet provided, SimpleXMLElement is used to create a SimpleXMLElement object from an XML string, and then the children() method is called on that object to get the children elements.

Rate this post

4 of 5 based on 5911 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us