php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23604 Problem with negative indices
Submitted: 2003-05-13 07:53 UTC Modified: 2003-08-03 12:56 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: nicolas at van-lancker dot be Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.3RC2-dev, 5.0.0b2-dev OS: any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nicolas at van-lancker dot be
New email:
PHP Version: OS:

 

 [2003-05-13 07:53 UTC] nicolas at van-lancker dot be
This is what the documentation says :

If you omit a key, the maximum of the integer-indices is taken, and the new key will be that maximum + 1. As integers can be negative, this is also true for negative indices. Having e.g. the highest index being -6 will result in -5 being the new key. If no integer-indices exist yet, the key will be 0 (zero).

My code :

<?php
	$arr[-6] = "me";
	$arr[] = "you";
?>

"you" is not stored in $arr[-5] but in $arr[0]
$arr[-4] does not exist...

This behaviour is undesired I guess...



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-13 16:28 UTC] sniper@php.net
With latest CVS I get this:

array(2) {
  [-6]=>
  string(2) "me"
  [0]=>
  string(3) "you"
}

Obvious bug..but should it be fixed is another question.
(the backwards-compatibility hell..)

 [2003-05-14 01:16 UTC] nicolas at van-lancker dot be
Theoretically it should be fixed,
but as you said, it might result in practical problems : backwards-compatibility issues.
If the option to not fix it is taken, the documentation needs to be adapted and it becomes a documentation bug.

Thanks for looking at the problem and keep up the good work.
 [2003-08-03 12:56 UTC] iliaa@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

Duplicate of bug #20548 (the cause is the same).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Aug 14 21:00:03 2025 UTC