note 24808 rejected from language.types.type-juggling by jmcastagnetto

From: Date: Thu, 29 Aug 2002 20:38:07 +0000
Subject: note 24808 rejected from language.types.type-juggling by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-35999@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.

« previous php.notes (#35999) next »