svn: /phpdoc/en/trunk/language/types/ string.xml
| From: | Justin Martin | Date: | Sat, 13 Nov 2010 03:46:44 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/types/ string.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-7410@lists.php.net to get a copy of this message | ||
frozenfire Sat, 13 Nov 2010 03:46:44 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=305306
Log:
Cleaned up simple string variable parsing example, as per bug #53254.
Bug: http://bugs.php.net/53254 (Assigned) Strings variable
parsing - misplaced examples
Changed paths:
U phpdoc/en/trunk/language/types/string.xml
Modified: phpdoc/en/trunk/language/types/string.xml
===================================================================
--- phpdoc/en/trunk/language/types/string.xml 2010-11-13 03:13:40 UTC (rev 305305)
+++ phpdoc/en/trunk/language/types/string.xml 2010-11-13 03:46:44 UTC (rev 305306)
@@ -513,14 +513,20 @@
<programlisting role="php">
<![CDATA[
<?php
-$beer = 'Heineken';
-echo "$beer's taste is great"; // works; "'" is an invalid character
for variable names
-echo "He drank some $beers"; // won't work; 's' is a valid character for
variable names but the variable is "$beer"
-echo "He drank some ${beer}s"; // works
-echo "He drank some {$beer}s"; // works
+$juice = "apple";
+
+echo "He drank some $juice juice.".PHP_EOL;
+echo "He drank some juice made of $juices."; // Invalid. "s" is a valid
character for a variable name, but the variable is $juice.
?>
]]>
</programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+He drank some apple juice.
+He drank some juice made of .
+]]>
+ </screen>
</informalexample>
<simpara>
@@ -530,49 +536,48 @@
object properties as to simple variables.
</simpara>
- <informalexample>
+ <example><title>Simple syntax example</title>
<programlisting role="php">
<![CDATA[
<?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}.
+$juices = array("apple", "orange", "koolaid1" =>
"purple");
-// Show all errors
-error_reporting(E_ALL);
+echo "He drank some $juices[0] juice.".PHP_EOL;
+echo "He drank some $juices[1] juice.".PHP_EOL;
+echo "He drank some juice made of $juice[0]s.".PHP_EOL;
+echo "He drank some $juices[koolaid1] juice.".PHP_EOL;
-$fruits = array('strawberry' => 'red', 'banana' =>
'yellow');
+class people {
+ public $john = "John Smith";
+ public $jane = "Jane Smith";
+ public $robert = "Robert Paulsen";
+
+ public $smith = "Smith";
+}
-// Works, but note that this works differently outside a string
-echo "A banana is $fruits[banana].";
+$people = new people();
-// 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.";
+echo "$people->john drank some $juices[0] juice.".PHP_EOL;
+echo "$people->john then said hello to $people->jane.".PHP_EOL;
+echo "$people->john's wife greeted $people->robert.".PHP_EOL;
+echo "$people->robert greeted the two $people->smiths.";
?>
]]>
-<!-- XXX this won't work:
-echo "This square is $square->{width}00 centimeters broad.";
-// XXX: php developers: it would be consequent to make this work.
-// XXX: like the $obj->{expr} syntax outside a string works,
-// XXX: analogously to the ${expr} syntax for variable var's.
--->
</programlisting>
- </informalexample>
+ &example.outputs;
+ <screen>
+<![CDATA[
+He drank some apple juice.
+He drank some orange juice.
+He drank some juice made of s.
+He drank some purple juice.
+John Smith drank some apple juice.
+John Smith then said hello to Jane Smith.
+John Smith's wife greeted Robert Paulsen.
+Robert Paulsen greeted the two .
+]]>
+ </screen>
+ </example>
<simpara>
For anything more complex, you should use the complex syntax.