Skip to content

Commit 7eef7c9

Browse files
Reflection: access common function fields through zend_function.common
The `zend_function` union has both an `op_array` member for userland code, and an `internal_function` member for internal code. The elements at the start of each match, and are also made available under the `common` member which only has the fields present in both `op_array` and `internal_function`. For function pointers that have not been checked to determine if they are userland functions or internal functions, access common fields through `common`. While technically there shouldn't be a difference due to the common layout (up through the relevant fields), semantically accessing information about an internal function through `op_array` or about a userland function through `internal_function` does not make sense.
1 parent 0d680a2 commit 7eef7c9

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

ext/reflection/php_reflection.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ static inline bool is_closure_invoke(const zend_class_entry *ce, const zend_stri
193193
static zend_function *_copy_function(zend_function *fptr) /* {{{ */
194194
{
195195
if (fptr
196-
&& (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
196+
&& (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
197197
{
198198
zend_function *copy_fptr;
199199
copy_fptr = emalloc(sizeof(zend_function));
200200
memcpy(copy_fptr, fptr, sizeof(zend_function));
201-
copy_fptr->internal_function.function_name = zend_string_copy(fptr->internal_function.function_name);
201+
copy_fptr->common.function_name = zend_string_copy(fptr->common.function_name);
202202
return copy_fptr;
203203
} else {
204204
/* no copy needed */
@@ -210,9 +210,9 @@ static zend_function *_copy_function(zend_function *fptr) /* {{{ */
210210
static void _free_function(zend_function *fptr) /* {{{ */
211211
{
212212
if (fptr
213-
&& (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
213+
&& (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
214214
{
215-
zend_string_release_ex(fptr->internal_function.function_name, false);
215+
zend_string_release_ex(fptr->common.function_name, false);
216216
zend_free_trampoline(fptr);
217217
}
218218
}
@@ -930,7 +930,7 @@ static void _function_string(smart_str *str, const zend_function *fptr, const ze
930930
smart_str_appends(str, "function ");
931931
}
932932

933-
if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
933+
if (fptr->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
934934
smart_str_appendc(str, '&');
935935
}
936936
smart_str_append_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name));
@@ -948,7 +948,7 @@ static void _function_string(smart_str *str, const zend_function *fptr, const ze
948948
}
949949
_function_parameter_string(str, fptr, ZSTR_VAL(param_indent.s));
950950
smart_str_free(&param_indent);
951-
if ((fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) {
951+
if ((fptr->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) {
952952
smart_str_append_printf(str, " %s- %s [ ", indent, ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1]) ? "Tentative return" : "Return");
953953
if (ZEND_TYPE_IS_SET(fptr->common.arg_info[-1].type)) {
954954
zend_string *type_str = zend_type_to_string(fptr->common.arg_info[-1].type);
@@ -2160,7 +2160,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, returnsReference)
21602160

21612161
GET_REFLECTION_OBJECT_PTR(fptr);
21622162

2163-
RETURN_BOOL((fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0);
2163+
RETURN_BOOL((fptr->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0);
21642164
}
21652165
/* }}} */
21662166

@@ -2392,8 +2392,8 @@ ZEND_METHOD(ReflectionGenerator, getFunction)
23922392
zval closure;
23932393
ZVAL_OBJ(&closure, ZEND_CLOSURE_OBJECT(func));
23942394
reflection_function_factory(func, &closure, return_value);
2395-
} else if (func->op_array.scope) {
2396-
reflection_method_factory(func->op_array.scope, func, NULL, return_value);
2395+
} else if (func->common.scope) {
2396+
reflection_method_factory(func->common.scope, func, NULL, return_value);
23972397
} else {
23982398
reflection_function_factory(func, NULL, return_value);
23992399
}
@@ -3650,7 +3650,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, hasReturnType)
36503650

36513651
GET_REFLECTION_OBJECT_PTR(fptr);
36523652

3653-
RETVAL_BOOL((fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) && !ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1]));
3653+
RETVAL_BOOL((fptr->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) && !ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1]));
36543654
}
36553655
/* }}} */
36563656

@@ -3664,7 +3664,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getReturnType)
36643664

36653665
GET_REFLECTION_OBJECT_PTR(fptr);
36663666

3667-
if (!(fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1])) {
3667+
if (!(fptr->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1])) {
36683668
RETURN_NULL();
36693669
}
36703670

@@ -3682,7 +3682,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, hasTentativeReturnType)
36823682

36833683
GET_REFLECTION_OBJECT_PTR(fptr);
36843684

3685-
RETVAL_BOOL(fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1]));
3685+
RETVAL_BOOL(fptr->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1]));
36863686
}
36873687
/* }}} */
36883688

@@ -3696,7 +3696,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getTentativeReturnType)
36963696

36973697
GET_REFLECTION_OBJECT_PTR(fptr);
36983698

3699-
if (!(fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || !ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1])) {
3699+
if (!(fptr->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || !ZEND_ARG_TYPE_IS_TENTATIVE(&fptr->common.arg_info[-1])) {
37003700
RETURN_NULL();
37013701
}
37023702

0 commit comments

Comments
 (0)