php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53254 Strings variable parsing - misplaced examples
Submitted: 2010-11-07 19:14 UTC Modified: 2010-11-13 04:47 UTC
From: chealer at gmail dot com Assigned: frozenfire (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chealer at gmail dot com
New email:
PHP Version: OS:

 

 [2010-11-07 19:14 UTC] chealer at gmail dot com
Description:
------------
Strings variables parsing, documented on http://ca2.php.net/manual/en/language.types.string.php#language.types.string.parsing
, has two forms: the simple and the complex syntax. Examples for each syntax are given, but some complex examples are in the simple section:

<?php
// These examples are specific to using arrays inside of strings.
// When outside of a string, always quote array string keys and do not use
// {braces}.

// Show all errors
error_reporting(E_ALL);

$fruits = array('strawberry' => 'red', 'banana' => 'yellow');

// Works, but note that this works differently outside a string
echo "A banana is $fruits[banana].";

// Works
echo "A banana is {$fruits['banana']}.";

// Works, but PHP looks for a constant named banana first, as described below.
echo "A banana is {$fruits[banana]}.";

// Won't work, use braces.  This results in a parse error.
echo "A banana is $fruits['banana'].";

// Works
echo "A banana is " . $fruits['banana'] . ".";

// Works
echo "This square is $square->width meters broad.";

// Won't work. For a solution, see the complex syntax.
echo "This square is $square->width00 centimeters broad.";
?>

The examples of {$fruits['banana']} and {$fruits[banana]} (inside curly braces) already have equivalents in the complex syntax section.


Patches

variable-parsing-simpleexample-fix (last revision 2010-11-11 22:00 UTC by frozenfire@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-07 21:01 UTC] frozenfire@php.net
Perhaps the entire section on variable parsing should be rewritten. From the organization of the examples - or lack thereof - it looks like examples were added at different times, without consideration of the greater layout of the section.

The whole section could probably be pruned down to a dozen or so lines.
 [2010-11-09 05:06 UTC] frozenfire@php.net
-Status: Open +Status: Feedback
 [2010-11-10 22:58 UTC] frozenfire@php.net
-Status: Feedback +Status: Open
 [2010-11-10 22:58 UTC] frozenfire@php.net
Changing back to open since Feedback status doesn't show up as an open bug.
 [2010-11-11 23:00 UTC] frozenfire@php.net
The following patch has been added/updated:

Patch Name: variable-parsing-simpleexample-fix
Revision:   1289512825
URL:        http://bugs.php.net/patch-display.php?bug=53254&patch=variable-parsing-simpleexample-fix&revision=1289512825
 [2010-11-13 04:20 UTC] Kalle@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: frozenfire
 [2010-11-13 04:20 UTC] Kalle@php.net
Justin, I think the patch looks effective and good, go ahead and commit it :)
 [2010-11-13 04:46 UTC] frozenfire@php.net
Automatic comment from SVN on behalf of frozenfire
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=305306
Log: Cleaned up simple string variable parsing example, as per bug #53254.
 [2010-11-13 04:47 UTC] frozenfire@php.net
-Status: Assigned +Status: Closed
 [2010-11-13 04:47 UTC] frozenfire@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 02:00:02 2026 UTC