Re: Re: A little confusing thing on (mistakenly) geting aoffset fromstring with multi dim index.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux