note 75669 added to language.variables.variable

From: Date: Mon, 11 Jun 2007 13:07:38 +0000
Subject: note 75669 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-127384@lists.php.net to get a copy of this message
One interesting thing I found out: You can use "blank" strings in the curly braces, and even strings together with variables (as long as you use double quotes or concatenation). Concatenating constants and function calls are also possible. <?php define('ONE', 1); function one() { return 1; } $one = 1; ${"foo$one"} = 'foo'; echo $foo1; // foo ${'foo' . ONE} = 'bar'; echo $foo1; // bar ${'foo' . one()} = 'baz'; echo $foo1; // baz ?> This syntax doesn't work for functions: <?php $foo = 'info'; {"php$foo"}(); // Parse error // You'll have to do: $func = "php$foo"; $func(); ?> Note: Don't leave out the quotes on strings inside the curly braces, PHP won't handle that graciously. ---- Server IP: 69.147.83.197 Probable Submitter: 172.180.79.59 ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit -- https://master.php.net/note/edit/75669 Del: integrated -- https://master.php.net/note/delete/75669/integrated Del: useless -- https://master.php.net/note/delete/75669/useless Del: bad code -- https://master.php.net/note/delete/75669/bad+code Del: spam -- https://master.php.net/note/delete/75669/spam Del: non-english -- https://master.php.net/note/delete/75669/non-english Del: in docs -- https://master.php.net/note/delete/75669/in+docs Del: other reasons-- https://master.php.net/note/delete/75669 Reject -- https://master.php.net/note/reject/75669 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127384) next »