php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49085 Typo in code example
Submitted: 2009-07-28 06:29 UTC Modified: 2009-07-28 09:22 UTC
From: asukakenji at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: N/A
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: asukakenji at gmail dot com
New email:
PHP Version: OS:

 

 [2009-07-28 06:29 UTC] asukakenji at gmail dot com
Description:
------------
There is a typo in the code example.

Reproduce code:
---------------
Visit:
http://www.php.net/manual/en/simplexml.examples-basic.php

Expected result:
----------------
In example #4, line 7, it should be:

foreach ($xml->movies as $movie) {

Actual result:
--------------
This is shown instead (the first movie should be movies):

foreach ($xml->movie as $movie) {

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-28 09:22 UTC] rquadling@php.net
Adding another movie to the movies collection and then running the 
example works as expected.


<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   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.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>

 <movie>
  <title>Upfront and personal</title>
  <characters>
   <character>
    <name>Richardo</name>
    <actor>Richard Quadling</actor>
   </character>
   <character>
    <name>Ozzer</name>
    <actor>Oscar Quadling</actor>
   </character>
  </characters>
  <plot>
   With only a few days to go, they get the job done.
  </plot>
  <great-lines>
   <line>A monkey could have done it!</line>
  </great-lines>
  <rating type="thumbs">9</rating>
  <rating type="stars">6</rating>
 </movie>

</movies>
XML;

$xml = new SimpleXMLElement($xmlstr);

/* For each <movie> node, we echo a separate <plot>. */
foreach ($xml->movie as $movie) {
   echo $movie->plot, PHP_EOL;
}
?>


outputs ...


   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.


   With only a few days to go, they get the job done.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 06:00:01 2026 UTC