svn: /phpdoc/en/trunk/ appendices/migration54.xml language/types/array.xml

From: Date: Sat, 31 Mar 2012 09:22:45 +0000
Subject: svn: /phpdoc/en/trunk/ appendices/migration54.xml language/types/array.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9984@lists.php.net to get a copy of this message
yohgaki Sat, 31 Mar 2012 09:22:45 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=324661 Log: Improve array doc for string offset access. Changed paths: U phpdoc/en/trunk/appendices/migration54.xml U phpdoc/en/trunk/language/types/array.xml Modified: phpdoc/en/trunk/appendices/migration54.xml =================================================================== --- phpdoc/en/trunk/appendices/migration54.xml 2012-03-31 09:19:59 UTC (rev 324660) +++ phpdoc/en/trunk/appendices/migration54.xml 2012-03-31 09:22:45 UTC (rev 324661) @@ -112,6 +112,12 @@ and <literal>'5 foobar'</literal> are considered non-numeric and produce a <constant>E_WARNING</constant>, but are converted to 12 and 5 respectively, for backward compatibility reasons. </simpara> + <simpara> + Note: Following code returns different result. + </simpara> + <simpara> + $str='abc';var_dump(isset($str['x'])); // false for PHP 5.4 or later, but true for 5.3 or less + </simpara> </listitem> <listitem> <simpara> Modified: phpdoc/en/trunk/language/types/array.xml =================================================================== --- phpdoc/en/trunk/language/types/array.xml 2012-03-31 09:19:59 UTC (rev 324660) +++ phpdoc/en/trunk/language/types/array.xml 2012-03-31 09:22:45 UTC (rev 324661) @@ -118,6 +118,61 @@ </listitem> </itemizedlist> </para> + + <para> + From PHP 5.4, string offset access made consistent. As a result, some return values may be + different from older version. As of PHP 5.4, string offset should be integer or integer like + string, otherwise it will be in a warning. + </para> + + <example> + <title>String offset access example</title> + <programlisting role="php"> +<![CDATA[ +<?php +$str = 'abc'; + +var_dump($str['1']); // 5.4.0>=: "b", Older versions: "b" +var_dump(isset($str['1'])); // 5.4.0>=: true, Older versions: ture + +var_dump($str['1.0']); // 5.4.0>=: "b" with E_WARNING, Older versions: "b" +var_dump(isset($str['1.0'])); // 5.4.0>=: false, Older versions: true + +var_dump($str['x']); // 5.4.0>=: "a" with E_WARNING, Older versions: "a" +var_dump(isset($str['x'])); // 5.4.0>=: false, Older versions: true + +var_dump($str['1x']); // 5.4.0>=: "b", Older versions: "b" +var_dump(isset($str['1x'])); // 5.4.0>=: true, Older versions: ture +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +[php-5.3]$ php-5.3 test.php +string(1) "b" +bool(true) +string(1) "b" +bool(true) +string(1) "a" +bool(true) +string(1) "b" +bool(true) +[php-5.4]$ php-5.4 test.php +string(1) "b" +bool(true) + +Warning: Illegal string offset '1.0' in /tmp/t.php on line 7 +string(1) "b" +bool(false) + +Warning: Illegal string offset 'x' in /tmp/t.php on line 9 +string(1) "a" +bool(false) +string(1) "b" +bool(false) + </screen> + </example> <para> If multiple elements in the array declaration use the same key, only the last one

« previous php.doc.cvs (#9984) next »