php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74836 isset on zero-prefixed numeric indexes in array broken
Submitted: 2017-06-30 13:46 UTC Modified: 2017-07-03 06:57 UTC
From: sjon at hortensius dot net Assigned: dmitry (profile)
Status: Closed Package: Arrays related
PHP Version: 7.2.0alpha2 OS: 3v4l.org
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: sjon at hortensius dot net
New email:
PHP Version: OS:

 

 [2017-06-30 13:46 UTC] sjon at hortensius dot net
Description:
------------
there seems to be bug when using quoted numeric indexes combined with isset(). It works without the (redundant) 0 prefix: https://3v4l.org/NQvXb

Test script:
---------------
See https://3v4l.org/3fXr6


<?php

$a = "1234567890a";
var_dump($a["010"], isset($a["010"])); // true

Expected result:
----------------
string(1) "a"
bool(true)

Actual result:
--------------
string(1) "a"
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-01 11:01 UTC] bwoebi@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2017-07-01 11:01 UTC] bwoebi@php.net
Related: http://git.php.net/?p=php-src.git;a=commitdiff;h=8fe47a47cf30eb3bf50a5cdb4e07f6fa135d21c7

Assigning to Dmitry, the commits author.
 [2017-07-03 06:57 UTC] dmitry@php.net
Also see: https://3v4l.org/SDpff

<?php
$a = "1234567890a";
$b[10] = "42";
$i = "010";
var_dump($a["10"], isset($a["10"]));
var_dump($a["010"], isset($a["010"]));
var_dump($a[$i], isset($a[$i]));
var_dump($b["10"], isset($b["10"]));
var_dump($b["010"], isset($b["010"]));
var_dump($b[$i], isset($b[$i]));

Actual result:
--------------
string(1) "a"
bool(true)
string(1) "a"
bool(false)
string(1) "a"
bool(true)
string(2) "42"
bool(true)

Notice: Undefined index: 010 in /in/N9KcU on line 9
NULL
bool(false)

Notice: Undefined index: 010 in /in/N9KcU on line 10
NULL
bool(false) 

It seems, we interpret zero-prefexed numeric indexes inconsistently.
I think, we should disable string-to-number conversion for all zero-prefexed cases.
 [2017-07-04 04:24 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=bfa24e34889ec8840bc86c5c39afcfb353d06567
Log: Fixed bug #74836 (isset on zero-prefixed numeric indexes in array broken)
 [2017-07-04 04:24 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 10:01:28 2024 UTC