php / php/doc-en

Outdated description of array assignment without key

Open
#2,420 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Category: Documentation Category: Engine
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

PHP manual https://www.php.net/manual/en/language.types.array.php states,

As mentioned above, if no key is specified, the maximum of the existing int indices is taken, and the new key will be that maximum value plus 1 (but at least 0).

However, since PHP 8.0, the auto-incremented key can be nagative.

$xs = [-10 => ""];
$xs[] = 42;
var_dump($xs);

https://3v4l.org/a0MCI

In PHP 8.0 or later:

array(2) {
  [-10]=>
  string(0) ""
  [-9]=>
  int(42)
}

In PHP 7.4 or older:

array(2) {
  [-10]=>
  string(0) ""
  [0]=>
  int(42)
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the PHP manual's language.types.array.php page and find the description of array assignment without a key. Update the wording to account for PHP 8.0 and later, where the auto-incremented key can remain negative as shown by the provided example; verify that the documented behavior still distinguishes older PHP versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.