[dev] Re: [cvs] commit: horde/lib String.php
Chuck Hagenbuch
chuck at horde.org
Mon Jan 27 09:47:29 PST 2003
Quoting Michael M Slusarz <slusarz at bigworm.colorado.edu>:
> My numbers from this script work out to be that isset() is approximately
> 25% faster that array_key_exists(). So you are right about that
> (although I am not getting anywhere near 100% performance increases like
> you and/or Chuck).
Okay...
> Here's the catch though. isset() returns false if the value is set to
> null. Thus, the following script:
Right. However, how often are we checking for a value that could be null,
that isn't initialized to null explicitly?
[big snip]
> Thus the argument to keep array_key_exists() is to ensure correct
> handling of this kind of situation Horde-wide. It doesn't really matter
> to me - but these were the reasons I orginally wanted to switch to
> array_key_exists().
It's a tough call, imho. The optimization angle is very tempting; so is the
correctness angle. It seems a bit dangerous to try and arrive at a standard for:
1. when null is a valid value
2. when it isn't
... since that's not so obvious.
For what it's worth, !empty() seems to be as fast as isset() (makes
intuitive sense, since they're both engine-level calls). So perhaps:
1. use !empty() when you're checking for non-empty data.
2. use array_key_exists() when false or null is okay
would work? The potential third step is: use isset() when false is okay but
null isn't, but that seems a bit too complicated imho.
Thoughts?
-chuck
--
Charles Hagenbuch, <chuck at horde.org>
must ... find ... acorns ... *thud*
More information about the dev
mailing list