array_append() And Short Assignation

<?php

$x = [];
$x[] = 1;
$x[] += 2;
$x[] ??= 3;
$x[] *= 4;
$x[] **= 5;
$x[] |= 6;

print_r($x);

?>

PHP allows using short assignation operators with the array append operators. This means that the code adds 2 to the array append. No error is displayed, except in the case of ??=, who is yield a Fatal error, with an explicit “Cannot use [] for reading”.

In any case, all of those expressions make little sense : the short assignation operators shall exist on an existing value, not a new one. Here, it looks like the default value is null.

See Also

PHP Error Messages

PHP Features

Last updated: 14 July 2026