philip Thu Aug 31 01:57:26 2006 UTC
Modified files: /phpdoc/en/language types.xml Log: $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 http://cvs.php.net/viewvc.cgi/phpdoc/en/language/types.xml?r1=1.166&r2=1.167&diff_format=u Index: phpdoc/en/language/types.xml diff -u phpdoc/en/language/types.xml:1.166 phpdoc/en/language/types.xml:1.167 --- phpdoc/en/language/types.xml:1.166 Thu May 4 02:21:28 2006 +++ phpdoc/en/language/types.xml Thu Aug 31 01:57:26 2006 @@ -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 @@ <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 @@ $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 @@ 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>