Skip to content

Commit 57c1335

Browse files
committed
Don't check argument types for internal functions without type hinting
1 parent fcb98cb commit 57c1335

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Zend/zend_API.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,19 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
21382138
str_efree(lowercase_name);
21392139
break;
21402140
}
2141+
2142+
/* If types of arguments have to be checked */
2143+
if (reg_function->common.arg_info && reg_function->common.num_args) {
2144+
int i;
2145+
for (i = 0; i < reg_function->common.num_args; i++) {
2146+
if (reg_function->common.arg_info[i].class_name ||
2147+
reg_function->common.arg_info[i].type_hint) {
2148+
reg_function->common.fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
2149+
break;
2150+
}
2151+
}
2152+
}
2153+
21412154
if (scope) {
21422155
/* Look for ctor, dtor, clone
21432156
* If it's an old-style constructor, store it only if we don't have

Zend/zend_compile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ typedef struct _zend_try_catch_element {
212212
#define ZEND_ACC_RETURN_REFERENCE 0x4000000
213213
#define ZEND_ACC_DONE_PASS_TWO 0x8000000
214214

215+
/* function has arguments with type hinting */
216+
#define ZEND_ACC_HAS_TYPE_HINTS 0x10000000
217+
215218
char *zend_visibility_string(zend_uint fn_flags);
216219

217220

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
19511951
LOAD_OPLINE();
19521952

19531953
if (fbc->type == ZEND_INTERNAL_FUNCTION) {
1954-
if (fbc->common.arg_info) {
1954+
if (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) {
19551955
zend_uint i=0;
19561956
zval **p = (zval**)EX(function_state).arguments;
19571957
ulong arg_count = opline->extended_value;

Zend/zend_vm_execute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static int ZEND_FASTCALL zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_AR
530530
LOAD_OPLINE();
531531

532532
if (fbc->type == ZEND_INTERNAL_FUNCTION) {
533-
if (fbc->common.arg_info) {
533+
if (fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) {
534534
zend_uint i=0;
535535
zval **p = (zval**)EX(function_state).arguments;
536536
ulong arg_count = opline->extended_value;

0 commit comments

Comments
 (0)