On Thu, 2003-08-14 at 08:45, Ilia Alshanetsky wrote:
> Do we really need this function? I see 2 ways of 'implementing' this
> functionality in PHP without having to add another function. For example:
> (isset($var) || is_null($var)) or gettype($var).
>
> Ilia
Those ideas don't do the same thing, though. Try it with arrays:
-SNIP------------------------------------------------------------
>>>> 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)
>>>> Array testing with gettype()
$arr = array(1 => null, 2 => array(1 => 3, 2 => null));
gettype($arr[1]): yes (should be yes)
gettype($arr[2]): yes (should be yes)
Notice: Undefined offset: 3 in /home/torben/public_html/phptest/variable_exists.html on line 40
gettype($arr[3]): yes (should be no)
gettype($arr[1][2]): yes (should be no)
gettype($arr[2][1]): yes (should be yes)
gettype($arr[2][2]): yes (should be yes)
Notice: Undefined offset: 3 in /home/torben/public_html/phptest/variable_exists.html on line 44
gettype($arr[2][3]): yes (should be no)
>>>> Array testing with (isset() || is_null())
$arr = array(1 => null, 2 => array(1 => 3, 2 => null));
(isset($arr[1]) || is_null($arr[1])): yes (should be yes)
(isset($arr[2]) || is_null($arr[2])): yes (should be yes)
Notice: Undefined offset: 3 in /home/torben/public_html/phptest/variable_exists.html on line 51
(isset($arr[3]) || is_null($arr[3])): yes (should be no)
(isset($arr[1][2]) || is_null($arr[1][2])): yes (should be no)
(isset($arr[2][1]) || is_null($arr[2][1])): yes (should be yes)
(isset($arr[2][2]) || is_null($arr[2][2])): yes (should be yes)
Notice: Undefined offset: 3 in /home/torben/public_html/phptest/variable_exists.html on line 55
(isset($arr[2][3]) || is_null($arr[2][3])): yes (should be no)
-SNIP------------------------------------------------------------
--
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 ====-----