mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@288077 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
f3d27e9e9e
commit
d2f58ea7cb
1 changed files with 32 additions and 1 deletions
|
@ -649,10 +649,41 @@ echo "I'd like to have another {${ strrev('reeb') }}, hips";
|
|||
|
||||
<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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue