Skip to content

Commit beb002a

Browse files
committed
Fixed bug #79791
First throw the undefined variable warning, and then set the variable to null. Otherwise we're not guaranteed that it's actually null afterwards.
1 parent 6259eff commit beb002a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug #79790 ("Illegal offset type" exception during AST evaluation
77
not handled properly). (Nikita)
8+
. Fixed bug #79791 (Assertion failure when unsetting variable during binary
9+
op). (Nikita)
810

911
09 Jul 2020, PHP 8.0.0alpha2
1012

Zend/tests/bug79791.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #79791: Assertion failure when unsetting variable during binary op
3+
--FILE--
4+
<?php
5+
set_error_handler(function() {
6+
unset($GLOBALS['c']);
7+
});
8+
$c -= 1;
9+
var_dump($c);
10+
?>
11+
--EXPECT--
12+
int(-1)

Zend/zend_execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_RW(uint32_t var EXECUTE_
367367
zval *ret = EX_VAR(var);
368368

369369
if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
370-
ZVAL_NULL(ret);
371370
zval_undefined_cv(var EXECUTE_DATA_CC);
371+
ZVAL_NULL(ret);
372372
return ret;
373373
}
374374
return ret;

0 commit comments

Comments
 (0)