Re: [PHP] isset() and !=NULL

2004-03-28 Thread Dimiter Naydenov
David Risner [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Fri, 26 
Mar 2004 10:40:43 -0800, Marcjon Louwersheimer
 [EMAIL PROTECTED] said:
  Is there an easier way to do
  isset($variable) AND $variable != NULL
  ? I use this alot in my if statements, and I was wondering if there's an
  easier way to do it, maybe with a single function? Oh and another
  question... how does if ($variable) work? When does it evaluate true?
 
 Check out the is_null function.  Itd seems to combine the two.
 
 http://www.php.net/manual/en/function.is-null.php
and
 http://www.php.net/manual/en/language.types.null.php#language.types.null.syntax

As Rasmus noted, (!empty($var)) is a complete aquivalent to (isset($var)  $var != 
null). I ran some more extensive tests which show the following:

class MyClass
{
  var $field = 123;
  function MyClass() {}
}

1. $x = null;
2. $y = 0;
3. $z = '';
4. $w = 'xyz';
5. $t = 123;
6. $o = new MyClass();
7. // $v is not set

1. isset($x)  $x != NULL: []
2. isset($y)  $y != NULL: []
3. isset($z)  $z != NULL: []
4. isset($w)  $w != NULL: [1]
5. isset($t)  $t != NULL: [1]
6. isset($o)  $o != NULL: [1]
7. isset($v)  $v != NULL: []

1. isset($x): []
2. isset($y): [1]
3. isset($z): [1]
4. isset($w): [1]
5. isset($t): [1]
6. isset($o): [1]
7. isset($v): []

1. !empty($x): []
2. !empty($y): []
3. !empty($z): []
4. !empty($w): [1]
5. !empty($t): [1]
6. !empty($o): [1]
7. !empty($v): []

1. is_null($x): [1]
2. is_null($y): []
3. is_null($z): []
4. is_null($w): []
5. is_null($t): []
6. is_null($o): []
Notice: Undefined variable: v in c:\web\test.php on line 62
7. is_null($v): [1] 

Also, as you see is_null($var) throws a notice when the variable is not defined.

Hope this helps ;)

Regards,
Dimiter

[PHP] isset() and !=NULL

2004-03-26 Thread Marcjon Louwersheimer
Is there an easier way to do
isset($variable) AND $variable != NULL
? I use this alot in my if statements, and I was wondering if there's an
easier way to do it, maybe with a single function? Oh and another
question... how does if ($variable) work? When does it evaluate true?
-- 
  Marcjon

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() and !=NULL

2004-03-26 Thread Rasmus Lerdorf
if(!empty($variable))

On Fri, 26 Mar 2004, Marcjon Louwersheimer wrote:

 Is there an easier way to do
 isset($variable) AND $variable != NULL
 ? I use this alot in my if statements, and I was wondering if there's an
 easier way to do it, maybe with a single function? Oh and another
 question... how does if ($variable) work? When does it evaluate true?
 -- 
   Marcjon
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() and !=NULL

2004-03-26 Thread Robert Cummings
On Fri, 2004-03-26 at 13:46, Rasmus Lerdorf wrote:
 if(!empty($variable))

This will return false positives for cases where the variable has not
been set to null but HAS been set to the empty string or to a 0? This
isn't really the same as the OP requested. However, isset() also returns
false for variables assigned null values and so he is fine with just
isset() and skipping the check for != NULL.

Contrast the following code and output:

echo ' isset: ['.isset( $foo ).']'.\n;
echo '!empty: ['.(!empty( $foo )).']'.\n;

--  isset: []
-- !empty: []

-

$foo = null;
echo ' isset: ['.isset( $foo ).']'.\n;
echo '!empty: ['.(!empty( $foo )).']'.\n;

--  isset: []
-- !empty: []

-

$foo = 0;
echo ' isset: ['.isset( $foo ).']'.\n;
echo '!empty: ['.(!empty( $foo )).']'.\n;

--  isset: [1]
-- !empty: []

-

$foo = 0.0;
echo ' isset: ['.isset( $foo ).']'.\n;
echo '!empty: ['.(!empty( $foo )).']'.\n;

--  isset: [1]
-- !empty: []

-

$foo = '';
echo ' isset: ['.isset( $foo ).']'.\n;
echo '!empty: ['.(!empty( $foo )).']'.\n;

--  isset: [1]
-- !empty: []

-

$foo = 'blah';
echo ' isset: ['.isset( $foo ).']'.\n;
echo '!empty: ['.(!empty( $foo )).']'.\n;

--  isset: [1]
-- !empty: [1]

-

Cheers,
Rob.

 
 On Fri, 26 Mar 2004, Marcjon Louwersheimer wrote:
 
  Is there an easier way to do
  isset($variable) AND $variable != NULL
  ? I use this alot in my if statements, and I was wondering if there's an
  easier way to do it, maybe with a single function? Oh and another
  question... how does if ($variable) work? When does it evaluate true?
  -- 
Marcjon

-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() and !=NULL

2004-03-26 Thread David Risner
On Fri, 26 Mar 2004 10:40:43 -0800, Marcjon Louwersheimer
[EMAIL PROTECTED] said:
 Is there an easier way to do
 isset($variable) AND $variable != NULL
 ? I use this alot in my if statements, and I was wondering if there's an
 easier way to do it, maybe with a single function? Oh and another
 question... how does if ($variable) work? When does it evaluate true?

Check out the is_null function.  Itd seems to combine the two.

http://www.php.net/manual/en/function.is-null.php
   and
http://www.php.net/manual/en/language.types.null.php#language.types.null.syntax

-- 
David G. Risner
Software Engineer
California State University, Los Angeles
http://www.risner.org/david/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php