Empty string accessed as characters turning into array?!

From: Date: Sun, 13 Apr 2003 14:40:49 +0000
Subject: Empty string accessed as characters turning into array?!
Groups: php.general 
Request: Send a blank email to php-general+get-143667@lists.php.net to get a copy of this message
Try the following script: <?php $foo = ''; $foo{0} = 'b'; $foo{1} = 'a'; $foo{2} = 'r'; print "Test 1:\n"; print_r($foo); $foo = ' '; $foo{0} = 'b'; $foo{1} = 'a'; $foo{2} = 'r'; print "Test 2:\n"; print_r($foo) ?> The results of test 1 will be an array of "b","a","r". The results of test 2 will be the string "bar". I can see why this might happen with the deprecated way of accessing string characters with [], but shouldn't {} always leave it as a string?

« previous php.general (#143667) next »