NYCPHP Meetup

NYPHP.org

[nycphp-talk] ${$variable}

Hans Zaunere hans at nyphp.org
Wed Aug 27 21:32:28 EDT 2003


> however, my $0.02 on this is limit the occassions where you have mixed
> variable types.
> if it's boolean, use a strict boolean test
>     and stick to using either true/false or 0/1; don't mix up true/0 or
> 1/false
> use strict string checking for strings

I'm 100% with this, Brian.  While loose-typing can be very handy (when used explicitly), I've found it's more trouble when you don't pay attention to it.  I use strict type equality checking (===) *always* and will only do a loose check (==) when I need to for a specific reason.  I've been burned too much by forgetting all the sublties covered in this thread.

It's also a performance boost.  empty() is quite an expensive operation; use isset() where possible, simple boolean checks, ie if( $var ),  and casting.  Explicit casting is fantastic; implicit casts can make your heart jump, which is why:

$bar = 0;
if ($bar == '') {
   echo '<br />bar equals empty';
}

makes output, and using  if( $bar === '' )   wouldn't.

Southwell, right on - this is certainly one for the fundamentals.

H





More information about the talk mailing list