note 95184 added to language.types.string
| From: | " | Date: | Thu, 17 Dec 2009 09:58:54 +0000 |
| Subject: | note 95184 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164069@lists.php.net to get a copy of this message | ||
Empty strings seem to be no real strings, because they behave different to strings containing data.
Here is an example.
It is possible to change a character at a specific position using the square bracket notation:
<?php
$str = '0';
$str[0] = 'a';
echo $str."\n"; // => 'a'
?>
It is also possible to change a character with does not exist, if the index is "behind"
the end of the string:
<?php
$str = '0';
$str[1] = 'a';
echo $str."\n"; // => 0a
?>
But if you do that on an empty string, the string gets silently converted into an array:
<?php
$str = '';
$str[0] = 'a';
echo $str."\n"; // => Array
?>
----
Server IP: 212.124.37.9
Probable Submitter: 193.254.155.48
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit -- https://master.php.net/note/edit/95184
Del: integrated -- https://master.php.net/note/delete/95184/integrated
Del: useless -- https://master.php.net/note/delete/95184/useless
Del: bad code -- https://master.php.net/note/delete/95184/bad+code
Del: spam -- https://master.php.net/note/delete/95184/spam
Del: non-english -- https://master.php.net/note/delete/95184/non-english
Del: in docs -- https://master.php.net/note/delete/95184/in+docs
Del: other reasons-- https://master.php.net/note/delete/95184
Reject -- https://master.php.net/note/reject/95184
Search -- https://master.php.net/manage/user-notes.php