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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
17 + 12 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC