Re: Re: A little confusing thing on (mistakenly) geting aoffset fromstring with multi dim index.
| From: | Christoph Becker | Date: | Thu, 15 May 2014 12:08:25 +0000 |
| Subject: | Re: Re: A little confusing thing on (mistakenly) geting aoffset fromstring with multi dim index. | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323325@lists.php.net to get a copy of this message | ||
Aziz Saleh wrote:
> Trying different versions of php give different results:
>
> http://sandbox.onlinephpfunctions.com/
>
> $string = 'this is a string';
> var_dump($string['check']);
>
> var_dump(isset($string['check']));
> var_dump(isset($string['check'][0]));
>
> Biggest change from 5.3 -> 5.5
Good catch! I was not aware of this change. I have double-checked that
on <http://3v4l.org/5GGYm>, and apparently, the behavior
has completely
turned around since PHP 5.4. The manual[1] notes:
| Non-numeric string offsets - e.g. $a['foo'] where $a is a string -
| now return false on isset() and true on empty(), and produce a
| E_WARNING if you try to use them. Offsets of types double, bool and
| null produce a E_NOTICE. Numeric strings (e.g. $a['2']) still work as
| before. Note that offsets like '12.3' and '5 foobar' are considered
| non-numeric and produce a E_WARNING, but are converted to 12 and 5
| respectively, for backward compatibility reasons. Note: Following
| code returns different result. $str='abc';var_dump(isset($str['x']));
| // false for PHP 5.4 or later, but true for 5.3 or less
I've also found a related (documentation) bug report:
<https://bugs.php.net/bug.php?id=61507>.
[1] <http://www.php.net/manual/en/migration54.incompatible.php>
--
Christoph M. Becker