Doc #53254 [Fbk->Opn]: Strings variable parsing - misplaced examples
| From: | frozenfire@php.net | Date: | Wed, 10 Nov 2010 21:58:49 +0000 |
| Subject: | Doc #53254 [Fbk->Opn]: Strings variable parsing - misplaced examples | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5518@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53254&edit=1
ID: 53254
Updated by: frozenfire@php.net
Reported by: chealer at gmail dot com
Summary: Strings variable parsing - misplaced examples
-Status: Feedback
+Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
New Comment:
Changing back to open since Feedback status doesn't show up as an open
bug.
Previous Comments:
------------------------------------------------------------------------
[2010-11-07 21:01:00] 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-07 19:14:08] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53254&edit=1