[nycphp-talk] Handling empty values in hashes
Daniel Convissor
danielc at analysisandsolutions.com
Thu Jul 17 17:20:45 EDT 2008
Paul:
On Thu, Jul 17, 2008 at 02:58:00PM -0400, paul at devonianfarm.com wrote:
>
> isset($array[$key])
> how's that different from array_key_exists?
isset() thinks NULL is not set. Similarly, empty() can be used for stuff
like this, but of course, it thinks NULL, 0, FALSE and "" are all the
same. Which function to use depends on how your program needs to work.
> http://gen5.info/q/2008/07/17/
> the-semantics-of-dictionaries-maps-and-hashtables
> tries to capture a similar logic into a single function, array_get()
Sure, that works. But I wouldn't take this person's advice too seriously
since they're talking about using isset() to see if a key exists and they
don't once discuss that their sample code on lines 11 and 15 can throw
notices.
> Overall I think logic like the code sample you give should be
> condensed into a function for several reasons: the most serious is
> that duplicated logic can hide errors.
Depends. I tend to like to see exactly what's happening right where
you're at. But if you're doing the same thing over and over, functions
are helpful.
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list