php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61302 SimpleXML documentation has an error.
Submitted: 2012-03-06 17:13 UTC Modified: 2012-03-15 02:01 UTC
From: timothy at green dot name Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Fedora Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: timothy at green dot name
New email:
PHP Version: OS:

 

 [2012-03-06 17:13 UTC] timothy at green dot name
Description:
------------
---
From manual page: http://www.php.net/simplexml.examples-basic
---
The documentation reads:
$movies = new SimpleXMLElement($xmlstr);
echo $movies->movie[0]->plot;
The above example will output:

   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.

No. That example will not output that. It outputs a SimpleXML Object. You need to cast it to a string to get that output. The documentation should make this clearer.

Test script:
---------------
<?php
header('Content-Type: text/plain');
$movies = file_get_contents('sample.movies.xml');
$xml = new SimpleXMLElement($movies);
$plot = (string)$xml->movie->plot;
var_dump($plot);
foreach ($plot as $v) {
    var_dump($v);
}
exit(__FILE__ . ': ' . __LINE__);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-15 02:01 UTC] dtajchreber@php.net
http://codepad.org/720OYnFR

In short, echo $obj; that has a __toString method defined gives you a string.

http://svn.php.net/viewvc/php/php-src/trunk/ext/simplexml/simplexml.c?
revision=321634&view=markup#l1839
 [2012-03-15 02:01 UTC] dtajchreber@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC