# Array behaviour change intentional?

- Thread: https://externals.io/message/2505
- Original archive: https://news-web.php.net/php.internals/2505
- Started by Lars Torben Wilson on 2003-06-21T19:19:29+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #2505 — Lars Torben Wilson — 2003-06-21T19:19:29+00:00

URL: https://externals.io/message/2505#2505

Hi there,

It seems that array appending has changed wrt negative indices. I had
just documented the new behaviour but now I'm not entirely sure whether 
I've just documented an unintentional change. Is this new behaviour what
is desired (i.e. skipping straight from some negative key to 0 when
appending with $arr[] = <expr>).



Thanks for any insight,


Torben


Test script:
<?php
$arr[-5] = "minus five";
$arr[] = "minus four";
var_dump($arr);
?>


Output PHP 4.2.1:
array(2) {
  [-5]=>
  string(10) "minus five"
  [-4]=>
  string(10) "minus four"
}


Output PHP 4.3.2:
array(2) {
  [-5]=>
  string(10) "minus five"
  [0]=>
  string(10) "minus four"
}


  


-- 
 Torben Wilson <torben@php.net>                        +1.604.709.0506
 http://www.thebuttlesschaps.com          http://www.inflatableeye.com
 http://www.hybrid17.com                  http://www.themainonmain.com
 -----==== Boycott Starbucks!  http://www.haidabuckscafe.com ====

---

## #2719 — Jani Taskinen — 2003-06-24T15:35:30+00:00

URL: https://externals.io/message/2505#2719 · In reply to: #2505

>Hi there,
>
>It seems that array appending has changed wrt negative indices. I had
>just documented the new behaviour but now I'm not entirely sure whether 
>I've just documented an unintentional change. Is this new behaviour what
>is desired (i.e. skipping straight from some negative key to 0 when
>appending with $arr[] = <expr>).
>
>
>
>Thanks for any insight,
>
>
>Torben
>
>
>Test script:
><?php
>$arr[-5] = "minus five";
>$arr[] = "minus four";
>var_dump($arr);
>?>
>
>
>Output PHP 4.2.1:
>array(2) {
>  [-5]=>
>  string(10) "minus five"
>  [-4]=>
>  string(10) "minus four"
>}

Output PHP 4.2.3:
array(2) {
  [-5]=>
  string(10) "minus five"
  [-4]=>
  string(10) "minus four"
}

Output PHP 4.3.1:
array(2) {
  [-5]=>
  string(10) "minus five"
  [0]=>
  string(10) "minus four"
}

>
>Output PHP 4.3.2:
>array(2) {
>  [-5]=>
>  string(10) "minus five"
>  [0]=>
>  string(10) "minus four"
>}

    Seems to have been changed in between 4.2.3 and 4.3.0.
    There is/was some bug reports about this too, iirc.
    
    Not very critical, I don't think there are that many scripts
    using this?
    
    --Jani

---

## #2728 — Lars Torben Wilson — 2003-06-24T17:27:20+00:00

URL: https://externals.io/message/2505#2728 · In reply to: #2719

> 
> 
> > […]

>     Seems to have been changed in between 4.2.3 and 4.3.0.
>     There is/was some bug reports about this too, iirc.
>     
>     Not very critical, I don't think there are that many scripts
>     using this?
>     
>     --Jani

Probably not--but there are enough for people to have noticed and
complained.

At the very least it's hard to document the correct behaviour. :)
Essentially I just need to know what to write in the docs, because at
the moment we don't know what the intended behaviour is. Should I just
write that the behaviour of negative indices is undefined, as you
appear to be implying (i.e. unimportant and therefore possibly changing
at random?)


-- 
 Torben Wilson <torben@php.net>                        +1.604.709.0506
 http://www.thebuttlesschaps.com          http://www.inflatableeye.com
 http://www.hybrid17.com                  http://www.themainonmain.com
 -----==== Boycott Starbucks!  http://www.haidabuckscafe.com ====
