note 105722 modified in function.empty by danbrown

From: Date: Sat, 10 Sep 2011 14:52:59 +0000
Subject: note 105722 modified in function.empty by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183078@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://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). --was-- 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). http://php.net/manual/en/function.empty.php

« previous php.notes (#183078) next »