On Thu, 2003-08-14 at 16:27, Zeev Suraski wrote: > At 21:15 14/08/2003, walt boring wrote: > >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 > >> > >I for one would like to see something like variable_exists(), as I am very > >annoyed with > >the logic of isset() returning false if the variable exists and has a > >value of null. > > The name of the function in this case doesn't not fit the logic for > > isset(). The variable does exist and it IS in fact set, the value just > > so happens to be null. > > It's just that 'null' is not a value. > > The way PHP treats null value is identical to that of non existent values, > which is precisely why isset() behaves the way that it does. I'm not sure > what the logic is behind Ilia's alternatives, they won't behave any > differently whether $var exists and is null, or whether it doesn't exist at > all, and it's intentional. > > Zeev
Right--I wouldn't suggest that isset() be changed. But variable_exists() would (for instance) allow the programmer to clear up the weirdness introduced when they run into the fact that assigning NULL to a value causes it for all intents and purposes to no longer exist--unless that variable is an array element, in which case it does indeed still exist (as it must, e.g. in order to preserver db results of NULL) as can be proved with array_key_exists(). The other thing is that although assigning NULL to a value causes isset() to claim that the variable is not set, testing the value of a variable set to NULL does not behave the way a truly non-existent variable does (i.e. it won't throw a notice if you read from a NULL-assigned variable). All variable_exists() does is give a simple, completely consistent way to check for the existence of a variable, regardless of its value. -- Torben Wilson <[EMAIL PROTECTED]> +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 ====----- -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php