Discussion: variable
Afficher un message
Vieux 16/09/2007, 12h36   #7
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable

..oO(Sanders Kaufman)

>Michael Fesser wrote:
>
>> | Please note that variable variables cannot be used with PHP's
>> | Superglobal arrays within functions or class methods.

>
>I read that, and re-read it, and re-read it... and I can't figure out
>what it means. Can you re-phrase it?
>
>I was good right up to "within functions...". I use super globals
>within functions all the time.


A variable variable is something like that:

$foo = 'bar';
$bar = 42;

print ${$foo}; // prints 42

This means the name of the variable is taken from another (string)
variable. The same can be done with superglobals, but not if you're
inside a function or method:

function test() {
$foo = '_GET';
var_dump(${$foo}); // throws a notice
}

Micha
  Réponse avec citation
 
Page generated in 0,04187 seconds with 9 queries