Hi,

Slightly off-topic but, as I was looking for the way to add support for '$str[]=' assignments, I found something strange.

Just for curiosity, does someone know a reason for this :

$str = "abc";
$str[1]="z";
var_dump($str); // -> string(3) "zbc" -> Expected

$str = ""; // Empty string
$str[1]="z";
var_dump($str); // -> array(1) { [0]=>string(1) "z" } -> !!!

The input string is converted to an array if it is empty. This becomes still funnier with :

$str="a";
$str[] = 'z'; // -> Fatal error : [] operator not supported for strings

$str="";
$str[] = 'z'; // -> OK -> $str gets array(1) { [0]=>string(1) "z" }

Thoughts ?

Regards

François


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to