tstarling@svn.wikimedia.org schreef:
Revision: 40902 Author: tstarling Date: 2008-09-16 06:13:31 +0000 (Tue, 16 Sep 2008)
Log Message:
Fixed documentation. Don't use empty() to determine if an array has zero length, that's not what it does.
That's exactly what it does [1].
Roan Kattouw (Catrope)
Roan Kattouw wrote:
tstarling@svn.wikimedia.org schreef:
Revision: 40902 Author: tstarling Date: 2008-09-16 06:13:31 +0000 (Tue, 16 Sep 2008)
Log Message:
Fixed documentation. Don't use empty() to determine if an array has zero length, that's not what it does.
That's exactly what it does [1].
Roan Kattouw (Catrope)
No, it does the same thing as the "!" operator, except it also suppresses warnings. If you want to check if an array has zero length, you should just use "!", as I did in that commit, so that a typo in the variable name will still give you the appropriate warning. Or if you want to make it explicit that you are checking array length, you can use !count($array). empty() should only be used when you are sure you want to ignore warnings.
-- Tim Starling
On Tue, Sep 16, 2008 at 7:09 PM, Tim Starling tstarling@wikimedia.org wrote:
No, it does the same thing as the "!" operator, except it also suppresses warnings. If you want to check if an array has zero length, you should just use "!", as I did in that commit, so that a typo in the variable name will still give you the appropriate warning. Or if you want to make it explicit that you are checking array length, you can use !count($array). empty() should only be used when you are sure you want to ignore warnings.
In particular, "!empty( $foo )" can be a handy shortcut for "isset( $foo ) && $foo".
On Wed, Sep 17, 2008 at 9:09 AM, Tim Starling tstarling@wikimedia.org wrote:
No, it does the same thing as the "!" operator, except it also suppresses warnings. If you want to check if an array has zero length, you should just use "!", as I did in that commit, so that a typo in the variable name will still give you the appropriate warning. Or if you want to make it explicit that you are checking array length, you can use !count($array). empty() should only be used when you are sure you want to ignore warnings.
!count( $array ) is also something like 40 times faster than !( $array ), apparently.
On Tue, Sep 16, 2008 at 7:36 PM, Stephen Bain stephen.bain@gmail.com wrote:
!count( $array ) is also something like 40 times faster than !( $array ), apparently.
My quick tests show that !$array is significantly faster, as you'd expect, based on variants of this loop:
for( $i = 0; $i < 100000; $i++ ) { !count( $array ); }
However, if checking whether an array is empty is a bottleneck in your program, you deserve a small prize for the weirdness of your optimization problems.
wikitech-l@lists.wikimedia.org