Array/string offset [] vs. {} syntax

From: Date: Sat, 26 Aug 2000 17:56:32 +0000
Subject: Array/string offset [] vs. {} syntax
Groups: php.dev 
Request: Send a blank email to php-dev+get-30775@lists.php.net to get a copy of this message
I just noticed this because of Andre's bug report #6180: since string offset support using {} has been added, it appears that [] and {} may be used interchangeably for array indexing and string offsets, except for inside strings, where the {} doesn't work as I might have expected: $str = 'This is a test'; echo "Second char of \$str: ${str[2]}\n"; echo "Second char of \$str: {$str{2}}\n"; echo "Second char of \$str: $str{2}\n"; echo "Third char of \$str: " . $str[3] . "\n"; echo "Fifth char of \$str: " . $str{5} . "\n"; Gives output: Second char of $str: i Second char of $str: i Second char of $str: This is a test{2} Third char of $str: s Fifth char of $str: i Can we get a rundown at some point about what the full implications are, or if the support is complete yet? With the latest cvs, I get: $a = "Z"; $a{0} = "f"; print_r($a); // prints 'f' echo "\n"; $a = "Z"; $a{1} = "f"; print_r($a); // prints 'Z' echo "\n"; $a = "ZZ"; $a{1} = "f"; print_r($a); // prints 'Zf' echo "\n"; Is this what is expected, and should it be going in the manual? Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.dev (#30775) next »