|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39915 Trying to access the index of an integer should throw a warning
Submitted: 2006-12-20 23:31 UTC Modified: 2019-07-10 12:19 UTC
Avg. Score:3.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: thuejk at gmail dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
 [2006-12-20 23:31 UTC] thuejk at gmail dot com
Trying to access the index of an integer is not a well-defined operation IMO, having no reasonable meaning. In practice in PHP, it seems to simply return null in all cases.

I accidentally accessed an integer which I thought was a string. Because no error was returned it took me some time to track down the problem.

Therefore, I suggest that trying to access an index on an integer should throw an E_NOTICE or E_WARNING.

Reproduce code:
error_reporting(E_ALL | E_STRICT);

$a = 1234;
//This will print "", with no error raised.
echo '"'.$a[0].'"';

Expected result:

Actual result:
No error raised


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 00:41 UTC]
-Package: Feature/Change Request +Package: *General Issues
 [2015-01-09 00:41 UTC]
 [2019-07-10 12:19 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-07-10 12:19 UTC]
Will throw a notice in 7.4.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jan 25 01:03:34 2022 UTC