Re: [PHP] Newbie question about isset and binary conditionals

2004-06-07 Thread Al
That's a big help Mike. 

My server has the error level set such that my incorrect use of if($var) 
did not show undefined variables. Though everything seemed to work OK.

I'm going my code and using if( TRUE or FALSE) isset() and empty() as 
appropriate.

Al..

Mike Ford wrote:
On 07 June 2004 14:04, Al wrote:
 

I posted this previously; but the subject was misleading.
   

You seem to have several possible misconceptions in your posting -- this may
just be me misreading you, but anyway...
 

I could use one additional clarification regarding good practice.
As I understand the php manual the following is acceptable
and I assume
good practice.
$foo= TRUE;
   

Not only acceptable but encouraged.
 

if($foo) do..  ;  where $foo is a binary; but not
a variable.
   

$foo is always a variable -- it can contain values of several types, one of
which is Boolean (not binary -- that's just a way of representing integers)
TRUE/FALSE.
 

isset should be used for variables, such as;
isset($var) for variables and be careful with $var= ' ';
etc.  because
$var is assigned, i.e., "set".
   

To work out which test you need to use, it's crucial to understand what
evaluates to FALSE in a Boolean context (which the test of an if() statement
is.  This is covered in precise detail in the PHP manual at
http://www.php.net/manual/en/language.types.boolean.php#language.types.boole
an.casting, but to summarize:
  the following are considered FALSE: Boolean FALSE, numeric zero (0 or
0.0), the strings "" and "0", an empty array or object, and NULL; all other
values are TRUE.  In addition to this, an unset variable will be evaluated
as NULL, and hence considered FALSE, but PHP will also issue an undefined
variable warning in this case (which may or may not be suppressed by your
PHP configuration!).
On the other hand, isset($var) will return TRUE if $var has been set to any
value except NULL, and FALSE otherwise -- so an isset() test on all the
other values listed above (including FALSE!) will be TRUE.
Other tests you may want to look into are empty() http://www.php.net/empty
and is_null() http://www.php.net/is-null; there are also some handy tables
at http://uk.php.net/manual/en/types.comparisons.php to help you see what
the various tests return.
Cheers!
Mike
-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 
 

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


RE: [PHP] Newbie question about isset and binary conditionals

2004-06-07 Thread Ford, Mike [LSS]
On 07 June 2004 14:04, Al wrote:

> I posted this previously; but the subject was misleading.

You seem to have several possible misconceptions in your posting -- this may
just be me misreading you, but anyway...

> I could use one additional clarification regarding good practice.
> 
> As I understand the php manual the following is acceptable
> and I assume
> good practice.
> 
> $foo= TRUE;

Not only acceptable but encouraged.

> 
> if($foo) do..  ;  where $foo is a binary; but not
> a variable.

$foo is always a variable -- it can contain values of several types, one of
which is Boolean (not binary -- that's just a way of representing integers)
TRUE/FALSE.
 
> isset should be used for variables, such as;
> 
>  isset($var) for variables and be careful with $var= ' ';
> etc.  because
> $var is assigned, i.e., "set".

To work out which test you need to use, it's crucial to understand what
evaluates to FALSE in a Boolean context (which the test of an if() statement
is.  This is covered in precise detail in the PHP manual at
http://www.php.net/manual/en/language.types.boolean.php#language.types.boole
an.casting, but to summarize:

   the following are considered FALSE: Boolean FALSE, numeric zero (0 or
0.0), the strings "" and "0", an empty array or object, and NULL; all other
values are TRUE.  In addition to this, an unset variable will be evaluated
as NULL, and hence considered FALSE, but PHP will also issue an undefined
variable warning in this case (which may or may not be suppressed by your
PHP configuration!).

On the other hand, isset($var) will return TRUE if $var has been set to any
value except NULL, and FALSE otherwise -- so an isset() test on all the
other values listed above (including FALSE!) will be TRUE.

Other tests you may want to look into are empty() http://www.php.net/empty
and is_null() http://www.php.net/is-null; there are also some handy tables
at http://uk.php.net/manual/en/types.comparisons.php to help you see what
the various tests return.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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



[PHP] Newbie question about isset and binary conditionals

2004-06-07 Thread Al
I posted this previously; but the subject was misleading.
I could use one additional clarification regarding good practice.
As I understand the php manual the following is acceptable and I assume 
good practice.

$foo= TRUE;
if($foo) do..  ;  where $foo is a binary; but not a variable.
isset should be used for variables, such as;
isset($var) for variables and be careful with $var= ' '; etc.  because 
$var is assigned, i.e., "set".

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


[PHP] Newbie question about isset and binary conditionals

2004-06-07 Thread Al
I posted this previously; but the subject was misleading.
I could use one additional clarification regarding good practice.
As I understand the php manual the following is acceptable and I assume 
good practice.

$foo= TRUE;
if($foo) do..  ;  where $foo is a binary; but not a variable.
isset should be used for variables, such as;
isset($var) for variables and be careful with $var= ' '; etc.  because 
$var is assigned, i.e., "set".

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