Take a look at the following:
file1.php
$a = 1;
$$a = "one"; // $1 = one
var_dump( ${'1'} ); // string(3) "one"
$str = "1=_one&foo=bar";
parse_str($str);
var_dump( ${'1'}, $foo );
// string(3) "one"
// and not "_one", so apparently $1 is not overwritten by parse_str
print_r( get_defined_vars() );
/*
Array(
[a] => 1
[1] => one <----- index is 1
[str] => 1=_one&foo=bar
[1] => _one <----- index is 1, again ?!?
[foo] => bar
);*/
file2.php
$str = "1=_one&foo=bar";
parse_str($str);
var_dump( ${'1'}, $foo ); // will give "undefined variable: 1" and string(3) "bar"
print_r( get_defined_vars() );
/* if you run this from the command line you may have more variables in here:
Array(
[a] => 1
[str] => 1=_one&foo=bar
[1] => _one <--- variable 1 is defined here
[foo] => bar
);*/
- How is it possible to have a duplicate array index? (see example of file1).
- How come in the 2nd example, variable
$1
is undefined but does show up in theget_defined_vars()
array? How do I access it? - In example 1, how come
$1
is not overwritten byparse_str
?