Matthew Weier O'Phinney wrote:
The problem is that there are situations where isset() and empty() are
not appropriate checks. For instance, try this:

    $test = array('foo' => null);
    echo ((isset($test['foo'])) ? 'true' : 'false'); // echoes 'false'!

What about empty()?

    $test = array('foo' => null);
    echo ((empty($test['foo'])) ? 'true' : 'false'); // echoes 'true'
    echo ((empty($test['bar'])) ? 'true' : 'false'); // also echoes 'true'!

What does that mean? It means that if you want to test for the presence
of a key, you can't rely on isset() *or* empty()! array_key_exists() is
the only way to reliably verify that the key is present in the array.

I know. I posted exactly this case in my original mail as a caveat. However looking at several uses of the function call in ZF, I see that this is a case which is not specifically being checked for and therefore isset() or empty() can be good optimisations.

e.g. in the Standard Dispatcher's getControllerDirectory(), the corner case mentioned above doesn't come into it (in fact if the key does not exist, the function returns null, so if the index exists but is null, it return that null value, otherwise it returns a null value).

There may be areas where we could switch to using one or the other...
but as somebody else pointed out, these would be micro-optimizations.
It's better to spend our time working on the true bottlenecks -- class
loading, the dispatch loop, etc.

Indeed. Just take my comments as an tip that language constructs should be favoured over function calls if possible, and the more people that know this the better :)

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]

Reply via email to