Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Zend/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ static inline zend_result ct_eval_isset_dim(zval *result, uint32_t extended_valu
} else if (Z_TYPE_P(op1) == IS_STRING) {
// TODO
return FAILURE;
} else if (IS_PARTIAL_OBJECT(op1)) {
/* Objects may implement ArrayAccess or throw. */
return FAILURE;
} else {

@arnaud-lb arnaud-lb Oct 5, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could add an assertion here to check that op1 is actually a scalar.

It looks like that ct_eval_isset_dim() pre-dates IS_PARTIAL_OBJECT and we forgot to update it when introducing IS_PARTIAL_OBJECT. An assertion would have spotted the issue earlier.

ZEND_ASSERT(Z_TYPE_P(op1) <= IS_DOUBLE);
ZVAL_BOOL(result, (extended_value & ZEND_ISEMPTY));
return SUCCESS;
}
Expand Down
36 changes: 36 additions & 0 deletions ext/opcache/tests/opt/sccp_isset_dim_partial_object.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
SCCP: isset()/empty() on dimension of non-escaping object must not be evaluated
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
--EXTENSIONS--
opcache
--FILE--
<?php
class P {}

function f() {
$o = new P;
return isset($o[1]);
}

function g() {
$o = new P;
return empty($o[1]);
}

try {
var_dump(f());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(g());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot use object of type P as array
Cannot use object of type P as array
Loading