Bug #74836 [Asn]: isset on zero-prefixed numeric indexes in array broken

From: Date: Mon, 03 Jul 2017 06:57:49 +0000
Subject: Bug #74836 [Asn]: isset on zero-prefixed numeric indexes in array broken
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209779@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74836&edit=1

 ID:                 74836
 Updated by:         dmitry@php.net
 Reported by:        sjon at hortensius dot net
 Summary:            isset on zero-prefixed numeric indexes in array
                     broken
 Status:             Assigned
 Type:               Bug
 Package:            Arrays related
 Operating System:   3v4l.org
 PHP Version:        7.2.0alpha2
 Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2017-07-01 11:01:40] bwoebi@php.net

Related: http://git.php.net/?p=php-src.git;a=commitdiff;h=8fe47a47cf30eb3bf50a5cdb4e07f6fa135d21c7

Assigning to Dmitry, the commits author.

------------------------------------------------------------------------
[2017-06-30 13:46:55] 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)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74836&edit=1


Thread (4 messages)

« previous php.bugs (#209779) next »