[nycphp-talk] Casting and list
Hans Zaunere
hans at newyorkphp.com
Mon Dec 22 13:52:55 EST 2003
> How about defining an array at the top of all the variables
> you want to cast as an integer
>
> $intVars = array('id', 'somenumber');
>
> then a simple
>
> ist($id,$name,$somenumber) = mysql_fetch_row($result);
> foreach ($inVars as $iv) $$iv = (int) $$iv ;
That's not a bad idea.
> or you could make two SQL calls, one for things you want to
> be integers and the other for everything else, followed by an
array_map
> casting the contents of the integer-only call (returned as an
associative array,
> mind you) to int.
Ehh, negative on the two SQL calls. I do have a function that attempts
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
but it's a little heavy and annoying in some ways. Alas, the yin-yang
of a type-less language.
Thanks Jeff - that array up top might be a nice maintainable way to
workaround this so that future generations can read the code :)
H
More information about the talk
mailing list