Re: [PHP] Manual contradiction concerning string access?
On Tue, February 20, 2007 10:15 am, Christian Heinrich wrote: > today, I read in a german PHP forum about a problem with accessing an > offset of a string. > > For example, if you have a variable like > > $string = "this is my string"; > > and you want to access the third character at once, I would suggest to > use > > $string{2} > > so this will return the "i". > > The (german!) manual says about that: > (http://de.php.net/manual/de/language.types.string.php#language.types.string.substr) > >> *Anmerkung: * Für Abwärtskompatibilität können Sie für den selben >> Zweck immer noch die Array-Klammern verwenden. Diese Syntax wird >> jedoch seit PHP 4 missbilligt. > > (Translation:) > >> *Note: *For downwards compatibility you may use the array brackets >> as >> well. But as of PHP 4, this syntax is deprecated. > > The english manual says: (Link: > http://de.php.net/manual/en/language.types.string.php#language.types.string.substr > ) > >> *Note: * They may also be accessed using braces like $str{42} for >> the >> same purpose. However, using square array-brackets is preferred >> because the {braces} style is deprecated as of PHP 6. > > > I'm a little bit confused by now. Which style should I pick? I use PHP > 4 > and 5. Is there any other difference? > > It would be great if someone could solve that contradiction within the > manual, too. We have made a bit of a mess of this... In early versions of PHP, it was considered "good" by the PHP Dev Team to be able to access a string as an array. $third = $foo[2]; $foo[2] = 'j'; Later PHP Dev Team members thought that was "icky" and decided to change it to use {} and deprecated []. Still others thought it was icky and one should only use substr to read a string, and, I guess, never replace a single character directly in a string. Then, a backlash occurred, as far as I can tell, and [] was back in vogue, or at least {} was deprecated. There is still a camp that wants [] to die, and only have substr. The German translation is "out of date", by one round of changes in all this. I am not 100% certain of the future status of [], but will personally be pretty cranky if it goes away, as I happen to like it. I know others feel differently, however, and would prefer to not have yet another flame war on this issue, so am trying to present a balanced view. I suspect that even if [] is still deprecated, or again deprecated, that it won't disappear as a feature for a long time, because it's just "out there" in too much code, and will be almost impossible to find and "fix"... You may want to check in with the internals@ list, as this is really more their kind of question/discussion... YMMV NAIAA IANAL -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Manual contradiction concerning string access?
On Tue, 2007-02-20 at 17:21 +0100, Németh Zoltán wrote: > AFAIK the english manual is more up to date, so I would follow that > > greets > Zoltán Németh > > 2007. 02. 20, kedd keltezéssel 17.15-kor Christian Heinrich ezt írta: > > Dear list, > > > > today, I read in a german PHP forum about a problem with accessing an > > offset of a string. > > > > For example, if you have a variable like > > > > $string = "this is my string"; > > > > and you want to access the third character at once, I would suggest to use > > > > $string{2} Use [], internals recently (7 months or so ago) reversed their opinion of on deprecating [] for strings in favour of {}. The {} almost got deprecated itself, but was saved in lieu of user feedback on internals. So it would seem [] is the superior choice and {} may someday get cut. This is in spite of the PHP group original recommending {}. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Manual contradiction concerning string access?
AFAIK the english manual is more up to date, so I would follow that greets Zoltán Németh 2007. 02. 20, kedd keltezéssel 17.15-kor Christian Heinrich ezt írta: > Dear list, > > today, I read in a german PHP forum about a problem with accessing an > offset of a string. > > For example, if you have a variable like > > $string = "this is my string"; > > and you want to access the third character at once, I would suggest to use > > $string{2} > > so this will return the "i". > > The (german!) manual says about that: > (http://de.php.net/manual/de/language.types.string.php#language.types.string.substr) > > > *Anmerkung: * Für Abwärtskompatibilität können Sie für den selben > > Zweck immer noch die Array-Klammern verwenden. Diese Syntax wird > > jedoch seit PHP 4 missbilligt. > > (Translation:) > > > *Note: *For downwards compatibility you may use the array brackets as > > well. But as of PHP 4, this syntax is deprecated. > > The english manual says: (Link: > http://de.php.net/manual/en/language.types.string.php#language.types.string.substr > > ) > > > *Note: * They may also be accessed using braces like $str{42} for the > > same purpose. However, using square array-brackets is preferred > > because the {braces} style is deprecated as of PHP 6. > > > I'm a little bit confused by now. Which style should I pick? I use PHP 4 > and 5. Is there any other difference? > > It would be great if someone could solve that contradiction within the > manual, too. > > > Thanks in advance. > > > Sincere regards > Christian Heinrich > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Manual contradiction concerning string access?
Dear list, today, I read in a german PHP forum about a problem with accessing an offset of a string. For example, if you have a variable like $string = "this is my string"; and you want to access the third character at once, I would suggest to use $string{2} so this will return the "i". The (german!) manual says about that: (http://de.php.net/manual/de/language.types.string.php#language.types.string.substr) *Anmerkung: * Für Abwärtskompatibilität können Sie für den selben Zweck immer noch die Array-Klammern verwenden. Diese Syntax wird jedoch seit PHP 4 missbilligt. (Translation:) *Note: *For downwards compatibility you may use the array brackets as well. But as of PHP 4, this syntax is deprecated. The english manual says: (Link: http://de.php.net/manual/en/language.types.string.php#language.types.string.substr ) *Note: * They may also be accessed using braces like $str{42} for the same purpose. However, using square array-brackets is preferred because the {braces} style is deprecated as of PHP 6. I'm a little bit confused by now. Which style should I pick? I use PHP 4 and 5. Is there any other difference? It would be great if someone could solve that contradiction within the manual, too. Thanks in advance. Sincere regards Christian Heinrich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php