Re: Re: variable_exists() patch
| From: | Lars Torben Wilson | Date: | Thu, 14 Aug 2003 19:51:39 +0000 |
| Subject: | Re: Re: variable_exists() patch | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-3960@lists.php.net to get a copy of this message | ||
On Thu, 2003-08-14 at 12:59, Ilia Alshanetsky wrote:
> On August 14, 2003 03:33 pm, Robert Cummings wrote:
> > Actually isset() doesn't behave as it should:
> >
> > $foo = null;
> > echo isset( $foo );
>
> Not quite. To understand the nature of NULL you must consider the following.
> Suppose you have a variable $foo you wish to 'destroy' you can do so by doing
> unset($foo) or $foo = NULL;. In both cases the value of $foo will be
> destroyed, however the variable will remain, it's value will become NULL.
> Therefor isset() behaviour, which works by seeing if a variable exists and
> making sure that its value is not null, is correct and now flawed as you
> claim. This is true for other languages as well such as C, when a pointer's
> value is null that pointer is 'no set'.
>
> Ilia
unset($foo) is not the same as $foo = NULL, which is one way this
is useful:
<?php
echo "\$foo = null\n\n";
$foo = null;
echo "variable_exists(\$foo): " . (variable_exists($foo) ? 'yes' :
'no')
. " (should be yes)\n";
echo "isset(\$foo): " . (isset($foo) ? 'yes' : 'no') . " (should
be
yes)\n";
echo "unset(\$foo);\n";
unset($foo);
echo "variable_exists(\$foo): " . (variable_exists($foo) ? 'yes' :
'no')
. " (should be no)\n";
echo "isset(\$bar): " . (isset($bar) ? 'yes' : 'no') . " (should
be
no)\n";
?>
OUTPUT:
$foo = null
variable_exists($foo): yes (should be yes)
isset($foo): no (should be yes)
unset($foo);
variable_exists($foo): no (should be no)
isset($bar): 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 ====-----