Skip to content

array_unshift should allow empty reference #10034

@mvorisek

Description

@mvorisek

Description

The following code:

<?php

$arr = ['y' => []];
array_unshift($arr['x'], 'a', 'b');
print_r($arr);

https://3v4l.org/llgI6

Resulted in this output:

 Uncaught TypeError: array_unshift(): Argument #1 ($array) must be of type array, null given

But I expected this output instead:

Array
(
    [x] => Array
        (
            [0] => a
            [1] => b
        )
)

I would expect php to accept reference to null for array_unshift (and friend functions) and create empty array like $arr['x'][] = 'a' syntax does.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions