php.net |  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: 2015-01-09 00:41 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: thuejk at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-12-20 23:31 UTC] thuejk at gmail dot com
Description:
------------
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:
----------------
An E_NOTICE or E_WARNING.

Actual result:
--------------
No error raised

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 00:41 UTC] ajf@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2015-01-09 00:41 UTC] ajf@php.net
Related: https://bugs.php.net/bug.php?id=37676
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC