2008/6/16 Chris Stockton <[EMAIL PROTECTED]>: > Hello, > > On Sun, Jun 15, 2008 at 11:20 PM, Arvids Godjuks <[EMAIL PROTECTED] > > > wrote: > > > String is an array of chars, always was and is such in any programming > > language. So I see argument for {} as missing knowledge for some > programming > > basics. > > > > And I don't understand why are you arguing on this. This was decided for > > removal long ago - so just do it. > > > > Seems like you are missing some PHP programming basics. Strings are not an > array of chars, please go back to making ping pong in java c# or whatever > other little comp sci classes you took. PHP is not any of them. > Foreach("foo" as $key => $char) {}, after learning, please be quiet and let > andi answer my question on his ideas he had for improvements to the > existing > and once favored syntax. > > -Chris >
Sort of in response to "whatever other little comp sci classes you took" and sort of explaining what a user sees. I'm a self taught software developer and have been in paid employment for over 20 years and only in 2 jobs. So, even if I don't know everything about PHP's internals, my skills are good enough not to get me fired. In that time, I've used (to a different amount) COBOL, Sage Retrieve 4GL, C, Delphi, JS, PHP, MS DOS Batch files. In nearly all of these languages a "string" is a series of characters which can be accessed via an offset from the beginning of the "string". In many cases the syntax is the same as that of accessing an array element. In the languages where it is necessary to define the length of the string, defining an array and a string are done in similar ways. Not identically by any means, but the "user" impression is that they are similar. The example Chris gave was for iterating an array. Strings cannot be iterated in the same manner, but that doesn't mean you cannot traverse a string and an array in the same way. <?php $a = array(1,2,3,5,7,11,13,17,19); $s = 'abcegkmqs'; for ($i = 0 ; $i < 9 ; ++$i) { echo $a[$i], ' vs ', $s[$i], ' vs ', $s{$i}, PHP_EOL; } outputs ... 1 vs a vs a 2 vs b vs b 3 vs c vs c 5 vs e vs e 7 vs g vs g 11 vs k vs k 13 vs m vs m 17 vs q vs q 19 vs s vs s So, using the same syntax to access a string and an array, from a user's perspective, does suggest that a string is an array of characters. Please be a little more forgiving of users. My only criticism against the use of $s{$i} is that { } is used to "wrap" compound statements (say like begin / end in other languages/syntaxes). With that in mind, you should be able to put statements which have a return value of some sort which is then used to access the appropriate element. But I think that is getting very close to closures. $s{return some_complex_calc();} sort of thing (smells like JS). I would like this syntax as I don't want to create a real function for just 1 use - the function may not be reuseable, so it doesn't need to get into the namespace. But I think that's a different argument. So, to all the devs who read my missives, keep up the good work. I'm paid because of the work you do. Your efforts make my life easier. Thank you, Richard Quadling. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"