php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27430 SimpleXML - call to undefined method children()
Submitted: 2004-02-28 14:45 UTC Modified: 2004-03-07 10:23 UTC
From: zyxwvu at users dot sourceforge dot net Assigned:
Status: Not a bug Package: *XML functions
PHP Version: 5CVS-2004-02-28 (dev) OS: Windows XP Pro
Private report: No CVE-ID: None
 [2004-02-28 14:45 UTC] zyxwvu at users dot sourceforge dot net
Description:
------------
I've got this PHP code:

$xml = simplexml_load_file('file.xml');

foreach($xml-> children() as $name => $item){
  echo $name.'<br/>';
}

It was working with older PHP 5 snapshots (as I know, from January). But: I have installed the newest PHP snapshot, and it returns:

Fatal error: Call to undefined method simplexml_element::children() in myfile.php on line xxx

The same problem is with "xpath()" method. 

Reproduce code:
---------------
<?php
$xml = simplexml_load_string(
'<person>
 <child role="son">
  <child role="daughter"/>
 </child>
 <child role="daughter">
  <child role="son">
   <child role="son"/>
  </child>
 </child>
</person>');

foreach ($xml->children() as $second_gen) {
   echo ' The person begot a ' . $second_gen['role'];

   foreach ($second_gen->children() as $third_gen) {
       echo ' who begot a ' . $third_gen['role'] . ';';
   
       foreach ($third_gen->children() as $fourth_gen) {
           echo ' and that ' . $third_gen['role'] .
               ' begot a ' . $fourth_gen['role'];
       }
   }
}
?>

Expected result:
----------------
The person begot a son who begot a daughter; The person
begot a daughter who begot a son; and that son begot a son


Actual result:
--------------
Fatal error: Call to undefined method simplexml_element::children() in file etc. etc.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-28 15:51 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Those were removed in later releases.
 [2004-03-07 10:23 UTC] helly@php.net
Have a look at SPL's SimpleXMLIterator class.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 13:03:33 2021 UTC