$string{42} is indeed deprecated as of PHP 6, so let's document that.

Also, removed "string offset" information from the "type juggling" section.
This also closes bug #38645


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@219131 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2006-08-31 01:57:26 +00:00
parent 905c366619
commit 9bdd5ee1bf

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.166 $ -->
<!-- $Revision: 1.167 $ -->
<chapter id="language.types">
<title>Types</title>
@ -1090,7 +1090,8 @@ echo "I'd like to have another {${ strrev('reeb') }}, hips";
<note>
<simpara>
They may also be accessed using braces like <varname>$str{42}</varname>
for the same purpose. However, using square array-brackets is preferred.
for the same purpose. However, using square array-brackets is preferred
because the {braces} style is deprecated as of PHP 6.
</simpara>
</note>
<para>
@ -1114,7 +1115,7 @@ $last = $str[strlen($str)-1];
$str = 'Look at the sea';
$str[strlen($str)-1] = 'e';
// Alternative method using {}
// Alternative method using {} is deprecated as of PHP 6
$third = $str{2};
?>
@ -2446,41 +2447,22 @@ examples:
undefined.
</para>
<para>
Also, because PHP supports indexing into strings via offsets using
the same syntax as array indexing, the following example holds true
for all PHP versions:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = "1"; // $a is a string
$a[0] = "f"; // What about string offsets? What happens?
$a = 'car'; // $a is a string
$a[0] = 'b'; // $a is still a string
echo $a; // bar
?>
]]>
</programlisting>
</informalexample>
</para>
<para>
Since PHP (for historical reasons) supports indexing into strings
via offsets using the same syntax as array indexing, the example
above leads to a problem: should $a become an array with its first
element being "f", or should "f" become the first character of the
string $a?
</para>
<para>
The current versions of PHP interpret the second assignment as
a string offset identification, so $a becomes "f", the result
of this automatic conversion however should be considered
undefined. PHP 4 introduced the new curly bracket syntax to access
characters in string, use this syntax instead of the one presented
above:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = "abc"; // $a is a string
$a{1} = "f"; // $a is now "afc"
?>
]]>
</programlisting>
</informalexample>
See the section titled <link linkend="language.types.string.substr">String
access by character</link> for more information.
</para>