note 91181 added to language.variables.variable
| From: | php at ianco dot co dot uk | Date: | Thu, 28 May 2009 21:47:12 +0000 |
| Subject: | note 91181 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156126@lists.php.net to get a copy of this message | ||
<?php
// $variable-name = 'parse error';
// You can't do that but you can do this:
$a = 'variable-name';
$$a = 'hello';
echo $variable-name . ' ' . $$a; // Gives 0 hello
?>
For a particular reason I had been using some variable names with hyphens for ages. There was no
problem because they were only referenced via a variable variable. I only saw a parse error much
later, when I tried to reference one directly. It took a while to realise that illegal hyphens were
the cause because the parse error only occurs on assignment.
----
Server IP: 87.124.35.190
Probable Submitter: 84.92.139.196
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- https://master.php.net/note/edit/91181
Del: integrated -- https://master.php.net/note/delete/91181/integrated
Del: useless -- https://master.php.net/note/delete/91181/useless
Del: bad code -- https://master.php.net/note/delete/91181/bad+code
Del: spam -- https://master.php.net/note/delete/91181/spam
Del: non-english -- https://master.php.net/note/delete/91181/non-english
Del: in docs -- https://master.php.net/note/delete/91181/in+docs
Del: other reasons-- https://master.php.net/note/delete/91181
Reject -- https://master.php.net/note/reject/91181
Search -- https://master.php.net/manage/user-notes.php