note 24808 added to language.types.type-juggling
| From: | php-general at lists dot php dot net | Date: | Thu, 29 Aug 2002 02:25:54 +0000 |
| Subject: | note 24808 added to language.types.type-juggling | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35954@lists.php.net to get a copy of this message | ||
$a = "1"; // $a is a string
$a[0] = "f"; // What about string offsets? What happens?
The best option would be that the $a[0] unambiguously designates an array-index access, and not
substring access.
To access individual characters, one should have to use a "substring range" access using a
comma and a second value that specifies the range length (like in splice_array() for arrays):
$a[0,1] = "f";
which would replace the first character, after converting $a into a string.
A syntax like:
$a[0,0] = "x";
would be equivalent to:
$a = "x" . $a";
And:
$a[-1,0] = "x";
would become equivalent to:
$a .= "x";
To access individual characters, a shortcut that avoids specifying the length 1 would be:
$a[12,] = "x";
which replaces the 13th character in $a.
$a[strlen($a),] = "x";
would be valid and would pad "x" to $a, but:
$a[strlen($a)+1,] = "x";
would generate an exception.
--
http://www.php.net/manual/en/language.types.type-juggling.php
http://master.php.net/manage/user-notes.php?action=edit+24808
http://master.php.net/manage/user-notes.php?action=delete+24808
http://master.php.net/manage/user-notes.php?action=reject+24808