note 41470 modified in language.types.string by colder
| From: | colder@php.net | Date: | Tue, 17 Oct 2006 18:08:48 +0000 |
| Subject: | note 41470 modified in language.types.string by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118640@lists.php.net to get a copy of this message | ||
Here is a possible gotcha related to oddness involved with accessing strings by character past the
end of the string:
$string = 'a';
var_dump($string[2]); // string(0) ""
var_dump($string[7]); // string(0) ""
$string[7] === ''; // TRUE
It appears that anything past the end of the string gives an empty string.. However, when E_NOTICE
is on, the above examples will throw the message:
Notice: Uninitialized string offset: N in FILE on line LINE
This message cannot be specifically masked with @$string[7], as is possible when $string itself is
unset.
isset($string[7]); // FALSE
$string[7] === NULL; // FALSE
Even though it seems like a not-NULL value of type string, it is still considered unset.
--was--
Here is a possible gotcha related to oddness involved with accessing strings by character past the
end of the string:
$string = 'a';
var_dump($string{2}); // string(0) ""
var_dump($string{7}); // string(0) ""
$string{7} === ''; // TRUE
It appears that anything past the end of the string gives an empty string.. However, when E_NOTICE
is on, the above examples will throw the message:
Notice: Uninitialized string offset: N in FILE on line LINE
This message cannot be specifically masked with @$string{7}, as is possible when $string itself is
unset.
isset($string{7}); // FALSE
$string{7} === NULL; // FALSE
Even though it seems like a not-NULL value of type string, it is still considered unset.
http://php.net/manual/en/language.types.string.php