You may consider to use "empty" function that check if isset and not NULL
And also "!empty" inverse function.

Empty($var) ? DoSomethingIfNotSetOrNull() : DoOther();
Also it is true, I use a personnal function to check var ...
Something like that

Function variable_exists( $var )
{
        $return = empty($var) ? null : $var;
        return $return;
}
So my function check if var isset and not null and return null if not or
directly $var if false( = isset and not null in this case)

So !empty($var) = ( isset($var) AND !is_null($var) )
And, Empty($var) = ( !isset($var) AND is_null($var) )

Function :      empty
----------------------------------------
Inverse function : !empty
Syntax :        #bool empty( #mixed <var>)
----------------------------------------
Arguments : #mixed <var>
Return :        #bolean <true||false>
----------------------------------------
Note : empty is not really a function but a language structure, look at
php.net for more info 

-----Message d'origine-----
De : Stefan Walk [mailto:[EMAIL PROTECTED] 
Envoyé : samedi 16 août 2003 09:50
À : Thies C. Arntzen
Cc : Alan Knowles; Lars Torben Wilson; [EMAIL PROTECTED]; walt boring;
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Objet : Re: [PHP-DEV] variable_exists() patch

On Fri, Aug 15, 2003 at 11:36:00AM +0200, Thies C. Arntzen wrote:
> On Fri, Aug 15, 2003 at 07:41:48AM +0800, Alan Knowles wrote:
> > I hit this a couple of months ago.. trying to implement NULL support 
> > in dataobjects:
> > 
> > $do = DB_DataObject::factory('test'); $do->get(12); $do->birthday = 
> > null; $do->update();
> > 
> > was supposed to generate
> > SELECT * FROM test WHERE id=12;
> > UPDATE test SET birthday=NULL where id = 12;
> > 
> > or
> > 
> > $do = DB_DataObject::factory('test'); $do->birthday = null; 
> > $do->find();
> > 
> > to do
> > SELECT * FROM test WHERE birthday IS NULL;
> > 
> > but since there was no effective way to detect null, as apposed to 
> > unset..  I had to give up... - If this could be solved by
> > variable_exists() - even though var $birthday is defined.. It would 
> > be great..
> 
>     alan,
> 
>     you hit the "nail on the head" - zeev, do you see any way to
>     solve alans problem?
> 
>     re,
>     thies

class Foo {
  function dump() { 
    var_dump(array_key_exists('bar', (array)$this));
  }
}
$foo = new Foo;
$foo->bar = null;
$foo->dump();
// => bool(true)

It's not that hard to detect.
--
Regards,
Stefan Walk
<[EMAIL PROTECTED]>

--
PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit:
http://www.php.net/unsub.php





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to