php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73143 The string used as an array make syntax error
Submitted: 2016-09-22 10:27 UTC Modified: 2016-09-22 10:32 UTC
From: 442958506 at qq dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.6.26 OS: all
Private report: No CVE-ID: None
 [2016-09-22 10:27 UTC] 442958506 at qq dot com
Description:
------------
The string used as an array, anyway the key(string) is, the result is the first character of the string.


Test script:
---------------
$a = '844';
echo $a['id']; 



Expected result:
----------------
PHP Warning:  Illegal string offset 'id' in E:\xx\index.php on line 3
Warning: Illegal string offset 'id' in E:\xx\index.php on line 3
result: ''

Actual result:
--------------
PHP Warning:  Illegal string offset 'id' in E:\xx\index.php on line 3
Warning: Illegal string offset 'id' in E:\xx\index.php on line 3
result: 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-22 10:32 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-09-22 10:32 UTC] requinix@php.net
PHP is casting 'id' to an integer so it will output $a[0]. If you try $a["1.5"] then you will get the warning and PHP will output $a[1].
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Sep 27 21:05:53 2022 UTC