Re: Re: variable_exists() patch
| From: | Lars Torben Wilson | Date: | Thu, 14 Aug 2003 20:20:47 +0000 |
| Subject: | Re: Re: variable_exists() patch | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-3963@lists.php.net to get a copy of this message | ||
On Thu, 2003-08-14 at 13:17, Mårten Gustafson wrote:
> Lars Torben Wilson (torben@php.net) wrote:
> > unset($foo) is not the same as $foo = NULL, which is one way this
>
> According to the manual, it is.
> http://www.php.net/manual/en/language.types.null.php
>
> /mårten.
According to the behaviour of the language, it is not, as
evidenced by array_key_exists():
<?php
echo "<h3>Array testing with variable_exists()</h3>";
echo "\$arr = array(1 => null, 2 => array(1 => 3, 2 => null));\n\n";
$arr = array(1 => null, 2 => array(1 => 3, 2 => null));
echo "variable_exists(\$arr[1]): " . (variable_exists($arr[1]) ? 'yes' :
'no') . " (should be yes)\n";
echo "variable_exists(\$arr[2]): " . (variable_exists($arr[2]) ? 'yes' :
'no') . " (should be yes)\n";
echo "variable_exists(\$arr[3]): " . (variable_exists($arr[3]) ? 'yes' :
'no') . " (should be no)\n";
echo "variable_exists(\$arr[1][2]): " . (variable_exists($arr[1][2]) ?
'yes' : 'no') . " (should be no)\n";
echo "variable_exists(\$arr[2][1]): " . (variable_exists($arr[2][1]) ?
'yes' : 'no') . " (should be yes)\n";
echo "variable_exists(\$arr[2][2]): " . (variable_exists($arr[2][2]) ?
'yes' : 'no') . " (should be yes)\n";
echo "variable_exists(\$arr[2][3]): " . (variable_exists($arr[2][3]) ?
'yes' : 'no') . " (should be no)\n";
echo "\$arr[2][1] = NULL;\n";
$arr[2][1] = NULL;
echo "isset(\$arr[2][1]): " . (isset($arr[2][1]) ? 'yes' : 'no') .
"
(should be yes)\n";
echo "variable_exists(\$arr[2][1]): " . (variable_exists($arr[2][1]) ?
'yes' : 'no') . " (should be yes)\n";
echo "array_key_exists(1, \$arr[2]): " . (array_key_exists(1, $arr[2]) ?
'yes' : 'no') . " (should be yes)\n";
echo "unset(\$arr[2][2])\n";
unset($arr[2][2]);
echo "isset(\$arr[2][2]): " . (isset($arr[2][2]) ? 'yes' : 'no') .
"
(should be no)\n";
echo "variable_exists(\$arr[2][2]): " . (variable_exists($arr[2][2]) ?
'yes' : 'no') . " (should be no)\n";
echo "array_key_exists(2, \$arr[2]): " . (array_key_exists(2, $arr[2]) ?
'yes' : 'no') . " (should be no)\n";
?>
OUTPUT:
Array testing with variable_exists()
$arr = array(1 => null, 2 => array(1 => 3, 2 => null));
variable_exists($arr[1]): yes (should be yes)
variable_exists($arr[2]): yes (should be yes)
variable_exists($arr[3]): no (should be no)
variable_exists($arr[1][2]): no (should be no)
variable_exists($arr[2][1]): yes (should be yes)
variable_exists($arr[2][2]): yes (should be yes)
variable_exists($arr[2][3]): no (should be no)
$arr[2][1] = NULL;
isset($arr[2][1]): no (should be yes)
variable_exists($arr[2][1]): yes (should be yes)
array_key_exists(1, $arr[2]): yes (should be yes)
unset($arr[2][2])
isset($arr[2][2]): no (should be no)
variable_exists($arr[2][2]): no (should be no)
array_key_exists(2, $arr[2]): no (should be no)
--
Torben Wilson <torben@php.net> +1.604.709.0506
http://www.thebuttlesschaps.com http://www.inflatableeye.com
http://www.hybrid17.com http://www.themainonmain.com
-----==== Boycott Starbucks! http://www.haidabuckscafe.com ====-----