php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71926 "undefined offset" raised for existing offset
Submitted: 2016-03-30 20:22 UTC Modified: 2016-03-30 20:38 UTC
From: rvanvelzen at experty dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.0.4 OS: Debian 8.3
Private report: No CVE-ID: None
 [2016-03-30 20:22 UTC] 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)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-30 20:38 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2016-03-30 20:38 UTC] nikic@php.net
Duplicate of bug #71334.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 18:01:29 2024 UTC