Bug #71926 [Opn->Dup]: "undefined offset" raised for existing offset
| From: | nikic@php.net | Date: | Wed, 30 Mar 2016 20:38:21 +0000 |
| Subject: | Bug #71926 [Opn->Dup]: "undefined offset" raised for existing offset | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200247@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71926&edit=1
ID: 71926
Updated by: nikic@php.net
Reported by: rvanvelzen at experty dot com
Summary: "undefined offset" raised for existing offset
-Status: Open
+Status: Duplicate
Type: Bug
Package: Scripting Engine problem
Operating System: Debian 8.3
PHP Version: 7.0.4
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #71334.
Previous Comments:
------------------------------------------------------------------------
[2016-03-30 20:22:43] rvanvelzen at experty dot com
Description:
------------
We're currently upgrading to PHP7, and noticed a notice which wasn't present in PHP5.
In PHP5 there is a warning regarding modification of the array, due to the reference to
$sortingData. In PHP7 however, an offset is missing. Strangely, when var_dump'ing the indexes
of the array, the 0 index is present.
Test script:
---------------
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
$sortingData = [
0 => 10,
1 => 12,
// This key is magic - anything >= 8 (or a non-integer key) makes this script produce the
E_NOTICE
8 => 11,
];
uksort($sortingData, function ($a, $b) use (&$sortingData) {
return $sortingData[$a] > $sortingData[$b] ? -1 : 1;
});
var_dump($sortingData);
Expected result:
----------------
Warning: uksort(): Array was modified by the user comparison function in /home/richard/break.php on
line 15
array(3) {
[1]=>
int(12)
[8]=>
int(11)
[0]=>
int(10)
}
Actual result:
--------------
Notice: Undefined offset: 0 in /home/richard/break.php on line 14
array(3) {
[1]=>
int(12)
[8]=>
int(11)
[0]=>
int(10)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71926&edit=1