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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: 442958506 at qq dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 05:01:27 2024 UTC