php-src icon indicating copy to clipboard operation
php-src copied to clipboard

extract($GLOBALS, EXTR_REFS); is broken in php8.1

Open divinity76 opened this issue 4 years ago • 4 comments

Description

The following code:

<?php

$g=5;
(function(){
    extract($GLOBALS, EXTR_REFS);
    var_dump($g);
    $g=6;
})();
var_dump($g);

Resulted in this output:

int(5)
int(5)

as of 8.1, but in php <8.1 it results in this output:

int(5)
int(6)

3v4l: https://3v4l.org/VrkkL

PHP Version

PHP 8.1

Operating System

No response

divinity76 avatar Feb 04 '22 10:02 divinity76

This BC break is documented:

However, write access to the entire $GLOBALS array is no longer supported.

Do we need to improve the documentation?

cmb69 avatar Feb 04 '22 10:02 cmb69

TIL, thanks.

For example, array_pop($GLOBALS) will result in an error.

puzzling that we don't get an error in this case, maybe extract($GLOBALS, EXTR_REFS); should also throw an error? "EXTR_REFS" is explicitly requesting write access after all 🤔

divinity76 avatar Feb 04 '22 11:02 divinity76

This issue is not specific to extract(), but rather affects all parameters which @prefer-ref (you can grep these in *.stub.php; there are not many). Given that there is no warning/error when you pass a value, I don't think that passing $GLOBALS should warn/error either.

I guess instead we want to get rid of @prefer-ref altogether.

cmb69 avatar Feb 04 '22 13:02 cmb69

No feedback was provided. The issue is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so. Thank you.

github-actions[bot] avatar Feb 19 '22 00:02 github-actions[bot]