svn: /phpdoc/en/trunk/language/types/ string.xml
| From: | Torben Wilson | Date: | Sat, 05 Sep 2009 06:39:01 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/types/ string.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4857@lists.php.net to get a copy of this message | ||
torben Sat, 05 Sep 2009 06:39:01 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=288077
Log:
Noted that the values of static class variables and class constants
may be accessed as the names of variables in the local scope, but that
single-curly-brace syntax will not work with function or method calls
or static class variables or class constants.
Addresses bug #47369.
Bug: http://bugs.php.net/47369 (Open) use of {self::$} in a
string always triggers Notice: Undefined variable:
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 2009-09-05 02:50:19 UTC (rev 288076)
+++ phpdoc/en/trunk/language/types/string.xml 2009-09-05 06:39:01 UTC (rev 288077)
@@ -649,10 +649,41 @@
<note>
<para>
- Functions and method calls inside <literal>{$}</literal> work since PHP 5.
+ Functions, method calls, static class variables, and class
+ constants inside <literal>{$}</literal> work since PHP
+ 5. However, the value accessed will be interpreted as the name
+ of a variable in the scope in which the string is defined. Using
+ single curly braces (<literal>{}</literal>) will not work for
+ accessing the return values of functions or methods or the
+ values of class constants or static class variables.
</para>
</note>
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
+<?php
+// Show all errors.
+error_reporting(E_ALL);
+
+class beers {
+ const softdrink = 'rootbeer';
+ public static $ale = 'ipa';
+}
+
+$rootbeer = 'A & W';
+$ipa = 'Alexander Keith\'s';
+
+// This works; outputs: I'd like an A & W
+echo "I'd like an {${beers::softdrink}}\n";
+
+// This works too; outputs: I'd like an Alexander Keith's
+echo "I'd like an {${beers::$ale}}\n";
+?>
+]]>
+ </programlisting>
+ </informalexample>
+
</sect4>
</sect3>