From 19cbd580fd2bc41d87b31b82cefe6d862947c47e Mon Sep 17 00:00:00 2001 From: Torben Wilson Date: Thu, 10 Sep 2009 05:45:54 +0000 Subject: [PATCH] Document variable properties. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@288221 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/types/string.xml | 28 ++++++++++++++++++++++++++ language/variables.xml | 41 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/language/types/string.xml b/language/types/string.xml index 594bd2ae0a..f9e6c4f79f 100644 --- a/language/types/string.xml +++ b/language/types/string.xml @@ -646,6 +646,34 @@ echo "I'd like to have another {${ strrev('reeb') }}, hips"; --> + + + It is also possible to access class properties using variables + within strings using this syntax. + + + + +$bar}\n"; +echo "{$foo->$baz[1]}\n"; +?> +]]> + + &example.outputs; + +I am bar. +I am bar. + + diff --git a/language/variables.xml b/language/variables.xml index 84a7768ff4..257ce17ef5 100644 --- a/language/variables.xml +++ b/language/variables.xml @@ -721,9 +721,46 @@ echo "$a $hello"; wanted $$a as the variable and then the [1] index from that variable. The syntax for resolving this ambiguity is: ${$a[1]} for the first case and - ${$a}[1] for the second. + ${$a}[1] for the second. - + + + 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 $foo->$bar, then the local + scope will be examined for $bar and its value + will be used as the name of the property + of $foo. This is also true + if $bar is an array access. + + + + + Variable function example + +$bar . "\n"; +echo $foo->$baz[1] . "\n"; +?> +]]> + + &example.outputs; + +I am bar. +I am bar. + + + + Please note that variable variables cannot be used with PHP's