note 105722 added to function.empty
| From: | chris dot wisefool at gmail dot com | Date: | Fri, 09 Sep 2011 07:44:58 +0000 |
| Subject: | note 105722 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183064@lists.php.net to get a copy of this message | ||
Note that checking the existence of a subkey of an array when that subkey does not exist but the
parent does and is a string will return false for empty.
i.e.
<?php
$params = array('search'=>'1');
empty($params['search']['filter']); # returns false
?>
This is correct, per the documentation (http://at2.php.net/manual/en/language.types.string.php);
quite a bit down the page is the Warning: "Writing to an out of range offset pads the string
with spaces. Non-integer types are converted to integer." ) I didn't receive a warning but
perhaps that's correct too...depends on whether the string -> integer conversion is
considered "illegal": "Illegal offset type emits E_NOTICE."
(i.e. since $params['search'] is a string, the 'filter' subscript is converted
to 0, so the test becomes empty($params['search'][0]), which is obviously false), but it
tripped me up enough to mistakenly file a bug report (which I've since closed).
----
Server IP: 192.35.244.50
Probable Submitter: 84.114.192.204
----
Manual Page -- http://www.php.net/manual/en/function.empty.php
Edit -- https://master.php.net/note/edit/105722
Del: integrated -- https://master.php.net/note/delete/105722/integrated
Del: useless -- https://master.php.net/note/delete/105722/useless
Del: bad code -- https://master.php.net/note/delete/105722/bad+code
Del: spam -- https://master.php.net/note/delete/105722/spam
Del: non-english -- https://master.php.net/note/delete/105722/non-english
Del: in docs -- https://master.php.net/note/delete/105722/in+docs
Del: other reasons-- https://master.php.net/note/delete/105722
Reject -- https://master.php.net/note/reject/105722
Search -- https://master.php.net/manage/user-notes.php