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: 2019-07-10 12:19 UTC
Votes:3
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
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: thuejk at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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
 [2019-07-10 12:19 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-07-10 12:19 UTC] nikic@php.net
Will throw a notice in 7.4.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Apr 01 17:01:31 2025 UTC