Re: [RFC] Generalize support of negative string offsets

From: Date: Mon, 08 Feb 2016 15:09:53 +0000
Subject: Re: [RFC] Generalize support of negative string offsets
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-91114@lists.php.net to get a copy of this message
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

« previous php.internals (#91114) next »