mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Document variable properties.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@288221 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
459f5061ab
commit
19cbd580fd
2 changed files with 67 additions and 2 deletions
|
@ -646,6 +646,34 @@ echo "I'd like to have another {${ strrev('reeb') }}, hips";
|
|||
-->
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
|
||||
<para>
|
||||
It is also possible to access class properties using variables
|
||||
within strings using this syntax.
|
||||
</para>
|
||||
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class foo {
|
||||
var $bar = 'I am bar.';
|
||||
}
|
||||
|
||||
$foo = new foo();
|
||||
$bar = 'bar';
|
||||
$baz = array('foo', 'bar', 'baz', 'quux');
|
||||
echo "{$foo->$bar}\n";
|
||||
echo "{$foo->$baz[1]}\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
I am bar.
|
||||
I am bar.
|
||||
</screen>
|
||||
</informalexample>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
|
|
|
@ -721,9 +721,46 @@ echo "$a $hello";
|
|||
wanted <varname>$$a</varname> as the variable and then the [1]
|
||||
index from that variable. The syntax for resolving this ambiguity
|
||||
is: <varname>${$a[1]}</varname> for the first case and
|
||||
<varname>${$a}[1]</varname> for the second.
|
||||
<varname>${$a}[1]</varname> for the second.
|
||||
</simpara>
|
||||
|
||||
|
||||
<simpara>
|
||||
Class properties may also be accessed using variable property
|
||||
names. The variable property name will be resolved within the
|
||||
scope from which the call is made. For instance, if you have an
|
||||
expression such as <varname>$foo->$bar</varname>, then the local
|
||||
scope will be examined for <varname>$bar</varname> and its value
|
||||
will be used as the name of the property
|
||||
of <varname>$foo</varname>. This is also true
|
||||
if <varname>$bar</varname> is an array access.
|
||||
</simpara>
|
||||
|
||||
<para>
|
||||
<example>
|
||||
<title>Variable function example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class foo {
|
||||
var $bar = 'I am bar.';
|
||||
}
|
||||
|
||||
$foo = new foo();
|
||||
$bar = 'bar';
|
||||
$baz = array('foo', 'bar', 'baz', 'quux');
|
||||
echo $foo->$bar . "\n";
|
||||
echo $foo->$baz[1] . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
I am bar.
|
||||
I am bar.
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
|
||||
<warning>
|
||||
<simpara>
|
||||
Please note that variable variables cannot be used with PHP's
|
||||
|
|
Loading…
Reference in a new issue