Skip to content

Commit da68458

Browse files
authored
ZEND_INIT_FCALL is only produced when function exists at compile time (php#7728)
1 parent 91734fc commit da68458

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

UPGRADING.INTERNALS

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP 8.2 INTERNALS UPGRADE NOTES
66

77
3. Module changes
88

9+
4. OpCode changes
10+
911
========================
1012
1. Internal API changes
1113
========================
@@ -24,3 +26,14 @@ PHP 8.2 INTERNALS UPGRADE NOTES
2426
3. Module changes
2527
========================
2628

29+
========================
30+
4. OpCode changes
31+
========================
32+
33+
* The ZEND_INIT_FCALL opcode now asserts that the function exists in the symbol
34+
table as the function's existence is checked at compile time.
35+
For extensions modifying the function symbol table, setting
36+
CG(compiler_options) |= ZEND_COMPILE_IGNORE_USER_FUNCTIONS | ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS;
37+
will produce ZEND_INIT_FCALL_BY_NAME opcodes instead which check for the
38+
existence of the function at runtime.
39+

Zend/zend_vm_def.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,9 +3930,7 @@ ZEND_VM_HOT_HANDLER(61, ZEND_INIT_FCALL, NUM, CONST, NUM|CACHE_SLOT)
39303930
if (UNEXPECTED(fbc == NULL)) {
39313931
fname = (zval*)RT_CONSTANT(opline, opline->op2);
39323932
func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(fname));
3933-
if (UNEXPECTED(func == NULL)) {
3934-
ZEND_VM_DISPATCH_TO_HELPER(zend_undefined_function_helper);
3935-
}
3933+
ZEND_ASSERT(func != NULL && "Function existence must be checked at compile time");
39363934
fbc = Z_FUNC_P(func);
39373935
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
39383936
init_func_run_time_cache(&fbc->op_array);

Zend/zend_vm_execute.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,9 +3693,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_FCALL_SPEC_CO
36933693
if (UNEXPECTED(fbc == NULL)) {
36943694
fname = (zval*)RT_CONSTANT(opline, opline->op2);
36953695
func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(fname));
3696-
if (UNEXPECTED(func == NULL)) {
3697-
ZEND_VM_TAIL_CALL(zend_undefined_function_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU));
3698-
}
3696+
ZEND_ASSERT(func != NULL && "Function existence must be checked at compile time");
36993697
fbc = Z_FUNC_P(func);
37003698
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
37013699
init_func_run_time_cache(&fbc->op_array);

0 commit comments

Comments
 (0)