[Gllug] mySQL PHP

Bruce Richardson brichardson at lineone.net
Wed Jul 11 12:41:47 UTC 2001


On 7/11/01, 11:25:10 AM, Dave Cridland <dave at cridland.net> wrote 
regarding Re: [Gllug] mySQL PHP:


> On 10 Jul 2001 19:38:15 +0100, Bruce Richardson wrote:
> > On Tue, Jul 10, 2001 at 07:10:43PM +0100, Bruce Richardson wrote:
> > >   $var1 = $var1 ? $var : "default value";
> >
> > Sorry:
> >
> >     $var1 = $var1 ? $var1 : "default value";
> >
> > --
> > Bruce

> Although, in my quest for code that tells the programmer what's really
> going on, I'd be more specific:

> if( !isset( $var ) ) {
>       $var = $var_default;
> }

No.  Your code does not do the same as mine.  Your code tests to see 
if $var is set - my code tests whether $var has a TRUE value (i.e. any 
value other than FALSE) and the test fails if $var1 either has a value 
of FALSE or is unset.  A variable with a value of FALSE is set and 
your code misses it.

	If ($var) { $var = $var_default }

is correct.

Besides, not only is the ?: operator used in quite a few C-style 
languages but it is explained in the introductory section of the PHP 
manual.  Your quest is for code which will be understood by people who 
haven't bothered to learn the language.

-- 

Bruce





-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list