NYCPHP Meetup

NYPHP.org

[nycphp-talk] Casting and list

Hans Zaunere hans at newyorkphp.com
Mon Dec 22 16:39:32 EST 2003


> > > to do this type of thing.  It's a type-sensitive mysql_fetch_row()
> > > (which is really what I'd like):
> > >
> > > http://pcomd.net/mysql_get_row
>
> Assuming that this code will be executed on every (or most) database
> queries, it would be much more efficient to use a switch 
> statement instead of all those else/if's.

I was on the fence about this, too.  From what I've
heard/read/understood, switch statements become more efficient than
if/else when there are about 4 or more test cases (switch statements
have a considerable overhead to setup).  This is from C, so frankly I
don't know if it holds true under PHP, too.  I'd be interested to see
both cases run through some profiler and I'll change the PCOM
accordingly :)

> There should also optimally be a catch all, just incase all if's are
false.

The catch all is implied.  If the type isn't known, the type should be a
string, which is what mysql_fetch_row() itself always returns - so no
need to do any casting.

H



More information about the talk mailing list