mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Improve array doc for string offset access.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@324661 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
ee0afeeaed
commit
3e98008af4
2 changed files with 61 additions and 0 deletions
|
@ -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>
|
||||
|
|
|
@ -118,6 +118,61 @@ $array = [
|
|||
</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
|
||||
|
|
Loading…
Reference in a new issue