Skip to content

Commit a4c015b

Browse files
committed
Fix handling of nullsafe method in empty()
Fixes oss-fuzz #24627.
1 parent 05c5c93 commit a4c015b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Zend/tests/nullsafe_operator/030.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Empty on nullsafe method
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public function method($value) {
8+
return $value;
9+
}
10+
}
11+
12+
$null = null;
13+
var_dump(empty($null?->method()));
14+
$test = new Test;
15+
var_dump(empty($test?->method(false)));
16+
var_dump(empty($test?->method(42)));
17+
18+
?>
19+
--EXPECT--
20+
bool(true)
21+
bool(true)
22+
bool(false)

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8684,7 +8684,6 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
86848684

86858685
ZEND_ASSERT(ast->kind == ZEND_AST_ISSET || ast->kind == ZEND_AST_EMPTY);
86868686

8687-
zend_short_circuiting_mark_inner(var_ast);
86888687
if (!zend_is_variable(var_ast)) {
86898688
if (ast->kind == ZEND_AST_EMPTY) {
86908689
/* empty(expr) can be transformed to !expr */
@@ -8698,6 +8697,7 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
86988697
}
86998698
}
87008699

8700+
zend_short_circuiting_mark_inner(var_ast);
87018701
switch (var_ast->kind) {
87028702
case ZEND_AST_VAR:
87038703
if (is_this_fetch(var_ast)) {

0 commit comments

Comments
 (0)