Skip to content

Conversation

@Girgias
Copy link
Member

@Girgias Girgias commented Oct 19, 2025

Based on the patch from @nielsdos and split into different commits to explain what affects what.

@alexandre-daubois
Copy link
Member

Not approving as it's still in draft, but looks good. Thanks for taking care of this!

@Girgias Girgias linked an issue Oct 20, 2025 that may be closed by this pull request
@Girgias Girgias changed the base branch from master to PHP-8.5 October 20, 2025 16:00
@Girgias Girgias marked this pull request as ready for review October 21, 2025 12:24
Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Comment on lines 6281 to 6295
} else if (UNEXPECTED(Z_TYPE_P(offset) == IS_NULL)) {
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
if (UNEXPECTED(EG(exception))) {
zval_ptr_dtor_nogc(expr_ptr);
HANDLE_EXCEPTION();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, each new warning opens a way to modify some involved zval through the user error handler.
In this case, user error handler may probably unset() op1 and this may lead to use-after-free on attempt to add new element.

It's better to add related test(s) and fix problem at first place.

cc @iluuu1994 @nielsdos

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed:

set_error_handler(function ($errno, $errstr) {
    var_dump($errstr);
    global $a;
    unset($a);
});

$a = new stdClass;
$b = [0, null => $a];

I usually spot those, but missed this one.

I hope we can come up with a general solution to avoid these issues (#20018 / #12805).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test case and fix.

@Girgias Girgias merged commit 9a1b8a7 into php:PHP-8.5 Oct 29, 2025
10 checks passed
@Girgias Girgias deleted the 8.5-null-offset branch October 29, 2025 18:36
Girgias added a commit that referenced this pull request Oct 29, 2025
* PHP-8.5:
  Update NEWS for null deprecation bug fix
  Fix GH-20194: null offset deprecation not emitted for writes (#20238)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using null as an array offset is not deprecated

4 participants