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

Reply via email to