/Zend/zend_execute.c
C | 4504 lines | 3832 code | 504 blank | 168 comment | 1279 complexity | 7c5eab72c2e4612efe22639a649ff2bb MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /*
- +----------------------------------------------------------------------+
- | Zend Engine |
- +----------------------------------------------------------------------+
- | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.00 of the Zend license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.zend.com/license/2_00.txt. |
- | If you did not receive a copy of the Zend license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@zend.com so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@php.net> |
- | Zeev Suraski <zeev@php.net> |
- | Dmitry Stogov <dmitry@php.net> |
- +----------------------------------------------------------------------+
- */
- #define ZEND_INTENSIVE_DEBUGGING 0
- #include <stdio.h>
- #include <signal.h>
- #include "zend.h"
- #include "zend_compile.h"
- #include "zend_execute.h"
- #include "zend_API.h"
- #include "zend_ptr_stack.h"
- #include "zend_constants.h"
- #include "zend_extensions.h"
- #include "zend_ini.h"
- #include "zend_exceptions.h"
- #include "zend_interfaces.h"
- #include "zend_closures.h"
- #include "zend_generators.h"
- #include "zend_vm.h"
- #include "zend_dtrace.h"
- #include "zend_inheritance.h"
- #include "zend_type_info.h"
- #include "zend_smart_str.h"
- /* Virtual current working directory support */
- #include "zend_virtual_cwd.h"
- #ifdef HAVE_GCC_GLOBAL_REGS
- # if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386)
- # define ZEND_VM_FP_GLOBAL_REG "%esi"
- # define ZEND_VM_IP_GLOBAL_REG "%edi"
- # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__x86_64__)
- # define ZEND_VM_FP_GLOBAL_REG "%r14"
- # define ZEND_VM_IP_GLOBAL_REG "%r15"
- # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__powerpc64__)
- # define ZEND_VM_FP_GLOBAL_REG "r28"
- # define ZEND_VM_IP_GLOBAL_REG "r29"
- # elif defined(__IBMC__) && ZEND_GCC_VERSION >= 4002 && defined(__powerpc64__)
- # define ZEND_VM_FP_GLOBAL_REG "r28"
- # define ZEND_VM_IP_GLOBAL_REG "r29"
- # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__)
- # define ZEND_VM_FP_GLOBAL_REG "x27"
- # define ZEND_VM_IP_GLOBAL_REG "x28"
- # endif
- #endif
- #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
- # pragma GCC diagnostic ignored "-Wvolatile-register-var"
- register zend_execute_data* volatile execute_data __asm__(ZEND_VM_FP_GLOBAL_REG);
- # pragma GCC diagnostic warning "-Wvolatile-register-var"
- #endif
- #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
- # define EXECUTE_DATA_D void
- # define EXECUTE_DATA_C
- # define EXECUTE_DATA_DC
- # define EXECUTE_DATA_CC
- # define NO_EXECUTE_DATA_CC
- #else
- # define EXECUTE_DATA_D zend_execute_data* execute_data
- # define EXECUTE_DATA_C execute_data
- # define EXECUTE_DATA_DC , EXECUTE_DATA_D
- # define EXECUTE_DATA_CC , EXECUTE_DATA_C
- # define NO_EXECUTE_DATA_CC , NULL
- #endif
- #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
- # define OPLINE_D void
- # define OPLINE_C
- # define OPLINE_DC
- # define OPLINE_CC
- #else
- # define OPLINE_D const zend_op* opline
- # define OPLINE_C opline
- # define OPLINE_DC , OPLINE_D
- # define OPLINE_CC , OPLINE_C
- #endif
- #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
- # pragma GCC diagnostic ignored "-Wvolatile-register-var"
- register const zend_op* volatile opline __asm__(ZEND_VM_IP_GLOBAL_REG);
- # pragma GCC diagnostic warning "-Wvolatile-register-var"
- #else
- #endif
- #define _CONST_CODE 0
- #define _TMP_CODE 1
- #define _VAR_CODE 2
- #define _UNUSED_CODE 3
- #define _CV_CODE 4
- typedef int (ZEND_FASTCALL *incdec_t)(zval *);
- #define get_zval_ptr(op_type, node, type) _get_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
- #define get_zval_ptr_deref(op_type, node, type) _get_zval_ptr_deref(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
- #define get_zval_ptr_undef(op_type, node, type) _get_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
- #define get_op_data_zval_ptr_r(op_type, node) _get_op_data_zval_ptr_r(op_type, node EXECUTE_DATA_CC OPLINE_CC)
- #define get_op_data_zval_ptr_deref_r(op_type, node) _get_op_data_zval_ptr_deref_r(op_type, node EXECUTE_DATA_CC OPLINE_CC)
- #define get_zval_ptr_ptr(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC)
- #define get_zval_ptr_ptr_undef(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC)
- #define get_obj_zval_ptr(op_type, node, type) _get_obj_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
- #define get_obj_zval_ptr_undef(op_type, node, type) _get_obj_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
- #define get_obj_zval_ptr_ptr(op_type, node, type) _get_obj_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC)
- #define RETURN_VALUE_USED(opline) ((opline)->result_type != IS_UNUSED)
- static ZEND_FUNCTION(pass)
- {
- }
- ZEND_API const zend_internal_function zend_pass_function = {
- ZEND_INTERNAL_FUNCTION, /* type */
- {0, 0, 0}, /* arg_flags */
- 0, /* fn_flags */
- NULL, /* name */
- NULL, /* scope */
- NULL, /* prototype */
- 0, /* num_args */
- 0, /* required_num_args */
- NULL, /* arg_info */
- ZEND_FN(pass), /* handler */
- NULL, /* module */
- {NULL,NULL,NULL,NULL} /* reserved */
- };
- #define FREE_VAR_PTR_AND_EXTRACT_RESULT_IF_NECESSARY(free_var) do { \
- zval *__container_to_free = EX_VAR(free_var); \
- if (UNEXPECTED(Z_REFCOUNTED_P(__container_to_free))) { \
- zend_refcounted *__ref = Z_COUNTED_P(__container_to_free); \
- if (UNEXPECTED(!GC_DELREF(__ref))) { \
- zval *__zv = EX_VAR(opline->result.var); \
- if (EXPECTED(Z_TYPE_P(__zv) == IS_INDIRECT)) { \
- ZVAL_COPY(__zv, Z_INDIRECT_P(__zv)); \
- } \
- rc_dtor_func(__ref); \
- } \
- } \
- } while (0)
- #define FREE_OP(type, var) \
- if ((type) & (IS_TMP_VAR|IS_VAR)) { \
- zval_ptr_dtor_nogc(EX_VAR(var)); \
- }
- #define FREE_UNFETCHED_OP(type, var) \
- FREE_OP(type, var)
- #define FREE_OP_VAR_PTR(type, var) \
- FREE_OP(type, var)
- #define CV_DEF_OF(i) (EX(func)->op_array.vars[i])
- #define ZEND_VM_STACK_PAGE_SLOTS (16 * 1024) /* should be a power of 2 */
- #define ZEND_VM_STACK_PAGE_SIZE (ZEND_VM_STACK_PAGE_SLOTS * sizeof(zval))
- #define ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, page_size) \
- (((size) + ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval) \
- + ((page_size) - 1)) & ~((page_size) - 1))
- static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend_vm_stack prev) {
- zend_vm_stack page = (zend_vm_stack)emalloc(size);
- page->top = ZEND_VM_STACK_ELEMENTS(page);
- page->end = (zval*)((char*)page + size);
- page->prev = prev;
- return page;
- }
- ZEND_API void zend_vm_stack_init(void)
- {
- EG(vm_stack_page_size) = ZEND_VM_STACK_PAGE_SIZE;
- EG(vm_stack) = zend_vm_stack_new_page(ZEND_VM_STACK_PAGE_SIZE, NULL);
- EG(vm_stack_top) = EG(vm_stack)->top;
- EG(vm_stack_end) = EG(vm_stack)->end;
- }
- ZEND_API void zend_vm_stack_init_ex(size_t page_size)
- {
- /* page_size must be a power of 2 */
- ZEND_ASSERT(page_size > 0 && (page_size & (page_size - 1)) == 0);
- EG(vm_stack_page_size) = page_size;
- EG(vm_stack) = zend_vm_stack_new_page(page_size, NULL);
- EG(vm_stack_top) = EG(vm_stack)->top;
- EG(vm_stack_end) = EG(vm_stack)->end;
- }
- ZEND_API void zend_vm_stack_destroy(void)
- {
- zend_vm_stack stack = EG(vm_stack);
- while (stack != NULL) {
- zend_vm_stack p = stack->prev;
- efree(stack);
- stack = p;
- }
- }
- ZEND_API void* zend_vm_stack_extend(size_t size)
- {
- zend_vm_stack stack;
- void *ptr;
- stack = EG(vm_stack);
- stack->top = EG(vm_stack_top);
- EG(vm_stack) = stack = zend_vm_stack_new_page(
- EXPECTED(size < EG(vm_stack_page_size) - (ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval))) ?
- EG(vm_stack_page_size) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, EG(vm_stack_page_size)),
- stack);
- ptr = stack->top;
- EG(vm_stack_top) = (void*)(((char*)ptr) + size);
- EG(vm_stack_end) = stack->end;
- return ptr;
- }
- ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data, uint32_t var)
- {
- return EX_VAR(var);
- }
- static zend_always_inline zval *_get_zval_ptr_tmp(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- ZEND_ASSERT(Z_TYPE_P(ret) != IS_REFERENCE);
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_var(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- ZVAL_DEREF(ret);
- return ret;
- }
- static zend_never_inline ZEND_COLD zval* zval_undefined_cv(uint32_t var EXECUTE_DATA_DC)
- {
- if (EXPECTED(EG(exception) == NULL)) {
- zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
- zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
- }
- return &EG(uninitialized_zval);
- }
- static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op1(EXECUTE_DATA_D)
- {
- return zval_undefined_cv(EX(opline)->op1.var EXECUTE_DATA_CC);
- }
- static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op2(EXECUTE_DATA_D)
- {
- return zval_undefined_cv(EX(opline)->op2.var EXECUTE_DATA_CC);
- }
- #define ZVAL_UNDEFINED_OP1() _zval_undefined_op1(EXECUTE_DATA_C)
- #define ZVAL_UNDEFINED_OP2() _zval_undefined_op2(EXECUTE_DATA_C)
- static zend_never_inline ZEND_COLD zval *_get_zval_cv_lookup(zval *ptr, uint32_t var, int type EXECUTE_DATA_DC)
- {
- switch (type) {
- case BP_VAR_R:
- case BP_VAR_UNSET:
- ptr = zval_undefined_cv(var EXECUTE_DATA_CC);
- break;
- case BP_VAR_IS:
- ptr = &EG(uninitialized_zval);
- break;
- case BP_VAR_RW:
- zval_undefined_cv(var EXECUTE_DATA_CC);
- /* break missing intentionally */
- case BP_VAR_W:
- ZVAL_NULL(ptr);
- break;
- }
- return ptr;
- }
- static zend_always_inline zval *_get_zval_ptr_cv(uint32_t var, int type EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
- if (type == BP_VAR_W) {
- ZVAL_NULL(ret);
- } else {
- return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC);
- }
- }
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_cv_deref(uint32_t var, int type EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
- if (type == BP_VAR_W) {
- ZVAL_NULL(ret);
- return ret;
- } else {
- return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC);
- }
- }
- ZVAL_DEREF(ret);
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_R(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
- return zval_undefined_cv(var EXECUTE_DATA_CC);
- }
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_R(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
- return zval_undefined_cv(var EXECUTE_DATA_CC);
- }
- ZVAL_DEREF(ret);
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_IS(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_RW(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
- ZVAL_NULL(ret);
- zval_undefined_cv(var EXECUTE_DATA_CC);
- return ret;
- }
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_W(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- if (Z_TYPE_P(ret) == IS_UNDEF) {
- ZVAL_NULL(ret);
- }
- return ret;
- }
- static zend_always_inline zval *_get_zval_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC)
- {
- if (op_type & (IS_TMP_VAR|IS_VAR)) {
- if (!ZEND_DEBUG || op_type == IS_VAR) {
- return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
- } else {
- ZEND_ASSERT(op_type == IS_TMP_VAR);
- return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
- }
- } else {
- if (op_type == IS_CONST) {
- return RT_CONSTANT(opline, node);
- } else if (op_type == IS_CV) {
- return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC);
- } else {
- return NULL;
- }
- }
- }
- static zend_always_inline zval *_get_op_data_zval_ptr_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC)
- {
- if (op_type & (IS_TMP_VAR|IS_VAR)) {
- if (!ZEND_DEBUG || op_type == IS_VAR) {
- return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
- } else {
- ZEND_ASSERT(op_type == IS_TMP_VAR);
- return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
- }
- } else {
- if (op_type == IS_CONST) {
- return RT_CONSTANT(opline + 1, node);
- } else if (op_type == IS_CV) {
- return _get_zval_ptr_cv_BP_VAR_R(node.var EXECUTE_DATA_CC);
- } else {
- return NULL;
- }
- }
- }
- static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_zval_ptr_deref(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC)
- {
- if (op_type & (IS_TMP_VAR|IS_VAR)) {
- if (op_type == IS_TMP_VAR) {
- return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
- } else {
- ZEND_ASSERT(op_type == IS_VAR);
- return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
- }
- } else {
- if (op_type == IS_CONST) {
- return RT_CONSTANT(opline, node);
- } else if (op_type == IS_CV) {
- return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC);
- } else {
- return NULL;
- }
- }
- }
- static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_op_data_zval_ptr_deref_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC)
- {
- if (op_type & (IS_TMP_VAR|IS_VAR)) {
- if (op_type == IS_TMP_VAR) {
- return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
- } else {
- ZEND_ASSERT(op_type == IS_VAR);
- return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
- }
- } else {
- if (op_type == IS_CONST) {
- return RT_CONSTANT(opline + 1, node);
- } else if (op_type == IS_CV) {
- return _get_zval_ptr_cv_deref_BP_VAR_R(node.var EXECUTE_DATA_CC);
- } else {
- return NULL;
- }
- }
- }
- static zend_always_inline zval *_get_zval_ptr_undef(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC)
- {
- if (op_type & (IS_TMP_VAR|IS_VAR)) {
- if (!ZEND_DEBUG || op_type == IS_VAR) {
- return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
- } else {
- ZEND_ASSERT(op_type == IS_TMP_VAR);
- return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
- }
- } else {
- if (op_type == IS_CONST) {
- return RT_CONSTANT(opline, node);
- } else if (op_type == IS_CV) {
- return EX_VAR(node.var);
- } else {
- return NULL;
- }
- }
- }
- static zend_always_inline zval *_get_zval_ptr_ptr_var(uint32_t var EXECUTE_DATA_DC)
- {
- zval *ret = EX_VAR(var);
- if (EXPECTED(Z_TYPE_P(ret) == IS_INDIRECT)) {
- ret = Z_INDIRECT_P(ret);
- }
- return ret;
- }
- static inline zval *_get_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC)
- {
- if (op_type == IS_CV) {
- return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC);
- } else /* if (op_type == IS_VAR) */ {
- ZEND_ASSERT(op_type == IS_VAR);
- return _get_zval_ptr_ptr_var(node.var EXECUTE_DATA_CC);
- }
- }
- static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC)
- {
- if (op_type == IS_UNUSED) {
- return &EX(This);
- }
- return get_zval_ptr(op_type, op, type);
- }
- static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_undef(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC)
- {
- if (op_type == IS_UNUSED) {
- return &EX(This);
- }
- return get_zval_ptr_undef(op_type, op, type);
- }
- static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC)
- {
- if (op_type == IS_UNUSED) {
- return &EX(This);
- }
- return get_zval_ptr_ptr(op_type, node, type);
- }
- static inline void zend_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr)
- {
- zend_reference *ref;
- if (EXPECTED(!Z_ISREF_P(value_ptr))) {
- ZVAL_NEW_REF(value_ptr, value_ptr);
- } else if (UNEXPECTED(variable_ptr == value_ptr)) {
- return;
- }
- ref = Z_REF_P(value_ptr);
- GC_ADDREF(ref);
- if (Z_REFCOUNTED_P(variable_ptr)) {
- zend_refcounted *garbage = Z_COUNTED_P(variable_ptr);
- if (GC_DELREF(garbage) == 0) {
- ZVAL_REF(variable_ptr, ref);
- rc_dtor_func(garbage);
- return;
- } else {
- gc_check_possible_root(garbage);
- }
- }
- ZVAL_REF(variable_ptr, ref);
- }
- static zend_never_inline zval* zend_assign_to_typed_property_reference(zend_property_info *prop_info, zval *prop, zval *value_ptr EXECUTE_DATA_DC)
- {
- if (!zend_verify_prop_assignable_by_ref(prop_info, value_ptr, EX_USES_STRICT_TYPES())) {
- return &EG(uninitialized_zval);
- }
- if (Z_ISREF_P(prop)) {
- ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(prop), prop_info);
- }
- zend_assign_to_variable_reference(prop, value_ptr);
- ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(prop), prop_info);
- return prop;
- }
- static zend_never_inline ZEND_COLD int zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
- {
- zend_error(E_NOTICE, "Only variables should be assigned by reference");
- if (UNEXPECTED(EG(exception) != NULL)) {
- return 0;
- }
- /* Use IS_TMP_VAR instead of IS_VAR to avoid ISREF check */
- Z_TRY_ADDREF_P(value_ptr);
- value_ptr = zend_assign_to_variable(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES());
- return 1;
- }
- static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(zend_property_info *prop, const char *type) {
- zend_string *type_str = zend_type_to_string(prop->type);
- zend_type_error(
- "Cannot auto-initialize an %s inside property %s::$%s of type %s",
- type,
- ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
- ZSTR_VAL(type_str)
- );
- zend_string_release(type_str);
- }
- static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_ref_error(zend_property_info *prop, const char *type) {
- zend_string *type_str = zend_type_to_string(prop->type);
- zend_type_error(
- "Cannot auto-initialize an %s inside a reference held by property %s::$%s of type %s",
- type,
- ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
- ZSTR_VAL(type_str)
- );
- zend_string_release(type_str);
- }
- static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_error(
- zend_property_info *prop) {
- zend_throw_error(NULL,
- "Cannot access uninitialized non-nullable property %s::$%s by reference",
- ZSTR_VAL(prop->ce->name),
- zend_get_unmangled_property_name(prop->name));
- }
- /* this should modify object only if it's empty */
- static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_throw_non_object_error(zval *object, zval *property OPLINE_DC EXECUTE_DATA_DC)
- {
- zend_string *tmp_property_name;
- zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
- if (opline->opcode == ZEND_PRE_INC_OBJ
- || opline->opcode == ZEND_PRE_DEC_OBJ
- || opline->opcode == ZEND_POST_INC_OBJ
- || opline->opcode == ZEND_POST_DEC_OBJ) {
- zend_throw_error(NULL,
- "Attempt to increment/decrement property '%s' of non-object",
- ZSTR_VAL(property_name));
- } else if (opline->opcode == ZEND_FETCH_OBJ_W
- || opline->opcode == ZEND_FETCH_OBJ_RW
- || opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG
- || opline->opcode == ZEND_ASSIGN_OBJ_REF) {
- zend_throw_error(NULL,
- "Attempt to modify property '%s' of non-object", ZSTR_VAL(property_name));
- } else {
- zend_throw_error(NULL,
- "Attempt to assign property '%s' of non-object", ZSTR_VAL(property_name));
- }
- zend_tmp_string_release(tmp_property_name);
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- static ZEND_COLD void zend_verify_type_error_common(
- const zend_function *zf, const zend_arg_info *arg_info,
- void **cache_slot, zval *value,
- const char **fname, const char **fsep, const char **fclass,
- zend_string **need_msg, const char **given_kind)
- {
- *fname = ZSTR_VAL(zf->common.function_name);
- if (zf->common.scope) {
- *fsep = "::";
- *fclass = ZSTR_VAL(zf->common.scope->name);
- } else {
- *fsep = "";
- *fclass = "";
- }
- *need_msg = zend_type_to_string_resolved(arg_info->type, zf->common.scope);
- if (value) {
- zend_bool has_class = ZEND_TYPE_HAS_CLASS(arg_info->type)
- || (ZEND_TYPE_FULL_MASK(arg_info->type) & MAY_BE_STATIC);
- if (has_class && Z_TYPE_P(value) == IS_OBJECT) {
- *given_kind = ZSTR_VAL(Z_OBJCE_P(value)->name);
- } else {
- *given_kind = zend_zval_type_name(value);
- }
- } else {
- *given_kind = "none";
- }
- }
- ZEND_API ZEND_COLD void zend_verify_arg_error(
- const zend_function *zf, const zend_arg_info *arg_info,
- int arg_num, void **cache_slot, zval *value)
- {
- zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
- const char *fname, *fsep, *fclass;
- zend_string *need_msg;
- const char *given_msg;
- if (EG(exception)) {
- /* The type verification itself might have already thrown an exception
- * through a promoted warning. */
- return;
- }
- if (value) {
- zend_verify_type_error_common(
- zf, arg_info, cache_slot, value,
- &fname, &fsep, &fclass, &need_msg, &given_msg);
- if (zf->common.type == ZEND_USER_FUNCTION) {
- if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
- zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given, called in %s on line %d",
- fclass, fsep, fname,
- arg_num, ZSTR_VAL(arg_info->name),
- ZSTR_VAL(need_msg), given_msg,
- ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno
- );
- } else {
- zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given",
- fclass, fsep, fname, arg_num, ZSTR_VAL(arg_info->name), ZSTR_VAL(need_msg), given_msg
- );
- }
- } else {
- zend_type_error("%s%s%s(): Argument #%d ($%s) must be of type %s, %s given",
- fclass, fsep, fname, arg_num, ((zend_internal_arg_info*) arg_info)->name, ZSTR_VAL(need_msg), given_msg
- );
- }
- zend_string_release(need_msg);
- } else {
- zend_missing_arg_error(ptr);
- }
- }
- static zend_bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg)
- {
- zend_long lval;
- double dval;
- zend_string *str;
- zend_bool bval;
- /* Type preference order: int -> float -> string -> bool */
- if (type_mask & MAY_BE_LONG) {
- /* For an int|float union type and string value,
- * determine chosen type by is_numeric_string() semantics. */
- if ((type_mask & MAY_BE_DOUBLE) && Z_TYPE_P(arg) == IS_STRING) {
- zend_uchar type = is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &lval, &dval, -1);
- if (type == IS_LONG) {
- zend_string_release(Z_STR_P(arg));
- ZVAL_LONG(arg, lval);
- return 1;
- }
- if (type == IS_DOUBLE) {
- zend_string_release(Z_STR_P(arg));
- ZVAL_DOUBLE(arg, dval);
- return 1;
- }
- } else if (zend_parse_arg_long_weak(arg, &lval)) {
- zval_ptr_dtor(arg);
- ZVAL_LONG(arg, lval);
- return 1;
- }
- }
- if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval)) {
- zval_ptr_dtor(arg);
- ZVAL_DOUBLE(arg, dval);
- return 1;
- }
- if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(arg, &str)) {
- /* on success "arg" is converted to IS_STRING */
- return 1;
- }
- if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval)) {
- zval_ptr_dtor(arg);
- ZVAL_BOOL(arg, bval);
- return 1;
- }
- return 0;
- }
- #if ZEND_DEBUG
- /* Used to sanity-check internal arginfo types without performing any actual type conversions. */
- static zend_bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask, zval *arg)
- {
- zend_long lval;
- double dval;
- zend_bool bval;
- if (type_mask & MAY_BE_LONG) {
- if (Z_TYPE_P(arg) == IS_STRING) {
- /* Handle this case separately to avoid the "non well-formed" warning */
- zend_uchar type = is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), NULL, &dval, 1);
- if (type == IS_LONG) {
- return 1;
- }
- if (type == IS_DOUBLE) {
- if ((type_mask & MAY_BE_DOUBLE)
- || (!zend_isnan(dval) && ZEND_DOUBLE_FITS_LONG(dval))) {
- return 1;
- }
- }
- }
- if (zend_parse_arg_long_weak(arg, &lval)) {
- return 1;
- }
- }
- if (type_mask & MAY_BE_DOUBLE) {
- if (Z_TYPE_P(arg) == IS_STRING) {
- /* Handle this case separately to avoid the "non well-formed" warning */
- if (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), NULL, NULL, 1) != 0) {
- return 1;
- }
- }
- if (zend_parse_arg_double_weak(arg, &dval)) {
- return 1;
- }
- }
- /* We don't call cast_object here, because this check must be side-effect free. As this
- * is only used for a sanity check of arginfo/zpp consistency, it's okay if we accept
- * more than actually allowed here. */
- if ((type_mask & MAY_BE_STRING) && (Z_TYPE_P(arg) < IS_STRING || Z_TYPE_P(arg) == IS_OBJECT)) {
- return 1;
- }
- if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval)) {
- return 1;
- }
- return 0;
- }
- #endif
- ZEND_API zend_bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, zend_bool strict, zend_bool is_internal_arg)
- {
- if (UNEXPECTED(strict)) {
- /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */
- if (!(type_mask & MAY_BE_DOUBLE) || Z_TYPE_P(arg) != IS_LONG) {
- return 0;
- }
- } else if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
- /* NULL may be accepted only by nullable hints (this is already checked).
- * As an exception for internal functions, null is allowed for scalar types in weak mode. */
- return is_internal_arg
- && (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING));
- }
- #if ZEND_DEBUG
- if (is_internal_arg) {
- return zend_verify_weak_scalar_type_hint_no_sideeffect(type_mask, arg);
- }
- #endif
- return zend_verify_weak_scalar_type_hint(type_mask, arg);
- }
- ZEND_COLD zend_never_inline void zend_verify_property_type_error(zend_property_info *info, zval *property)
- {
- zend_string *type_str;
- /* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */
- if (EG(exception)) {
- return;
- }
- type_str = zend_type_to_string(info->type);
- zend_type_error("Cannot assign %s to property %s::$%s of type %s",
- Z_TYPE_P(property) == IS_OBJECT ? ZSTR_VAL(Z_OBJCE_P(property)->name) : zend_get_type_by_const(Z_TYPE_P(property)),
- ZSTR_VAL(info->ce->name),
- zend_get_unmangled_property_name(info->name),
- ZSTR_VAL(type_str));
- zend_string_release(type_str);
- }
- static zend_class_entry *resolve_single_class_type(zend_string *name, zend_class_entry *self_ce) {
- if (zend_string_equals_literal_ci(name, "self")) {
- /* We need to explicitly check for this here, to avoid updating the type in the trait and
- * later using the wrong "self" when the trait is used in a class. */
- if (UNEXPECTED((self_ce->ce_flags & ZEND_ACC_TRAIT) != 0)) {
- return NULL;
- }
- return self_ce;
- } else if (zend_string_equals_literal_ci(name, "parent")) {
- return self_ce->parent;
- } else {
- return zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
- }
- }
- static zend_bool zend_check_and_resolve_property_class_type(
- zend_property_info *info, zend_class_entry *object_ce) {
- zend_class_entry *ce;
- if (ZEND_TYPE_HAS_LIST(info->type)) {
- zend_type *list_type;
- ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(info->type), list_type) {
- if (ZEND_TYPE_HAS_NAME(*list_type)) {
- zend_string *name = ZEND_TYPE_NAME(*list_type);
- ce = resolve_single_class_type(name, info->ce);
- if (!ce) {
- continue;
- }
- zend_string_release(name);
- ZEND_TYPE_SET_CE(*list_type, ce);
- } else {
- ce = ZEND_TYPE_CE(*list_type);
- }
- if (instanceof_function(object_ce, ce)) {
- return 1;
- }
- } ZEND_TYPE_LIST_FOREACH_END();
- return 0;
- } else {
- if (UNEXPECTED(ZEND_TYPE_HAS_NAME(info->type))) {
- zend_string *name = ZEND_TYPE_NAME(info->type);
- ce = resolve_single_class_type(name, info->ce);
- if (UNEXPECTED(!ce)) {
- return 0;
- }
- zend_string_release(name);
- ZEND_TYPE_SET_CE(info->type, ce);
- } else {
- ce = ZEND_TYPE_CE(info->type);
- }
- return instanceof_function(object_ce, ce);
- }
- }
- static zend_always_inline zend_bool i_zend_check_property_type(zend_property_info *info, zval *property, zend_bool strict)
- {
- ZEND_ASSERT(!Z_ISREF_P(property));
- if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(info->type, Z_TYPE_P(property)))) {
- return 1;
- }
- if (ZEND_TYPE_HAS_CLASS(info->type) && Z_TYPE_P(property) == IS_OBJECT
- && zend_check_and_resolve_property_class_type(info, Z_OBJCE_P(property))) {
- return 1;
- }
- uint32_t type_mask = ZEND_TYPE_FULL_MASK(info->type);
- ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC)));
- if ((type_mask & MAY_BE_ITERABLE) && zend_is_iterable(property)) {
- return 1;
- }
- return zend_verify_scalar_type_hint(type_mask, property, strict, 0);
- }
- static zend_always_inline zend_bool i_zend_verify_property_type(zend_property_info *info, zval *property, zend_bool strict)
- {
- if (i_zend_check_property_type(info, property, strict)) {
- return 1;
- }
- zend_verify_property_type_error(info, property);
- return 0;
- }
- zend_bool zend_never_inline zend_verify_property_type(zend_property_info *info, zval *property, zend_bool strict) {
- return i_zend_verify_property_type(info, property, strict);
- }
- static zend_never_inline zval* zend_assign_to_typed_prop(zend_property_info *info, zval *property_val, zval *value EXECUTE_DATA_DC)
- {
- zval tmp;
- ZVAL_DEREF(value);
- ZVAL_COPY(&tmp, value);
- if (UNEXPECTED(!i_zend_verify_property_type(info, &tmp, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(&tmp);
- return &EG(uninitialized_zval);
- }
- return zend_assign_to_variable(property_val, &tmp, IS_TMP_VAR, EX_USES_STRICT_TYPES());
- }
- ZEND_API zend_bool zend_value_instanceof_static(zval *zv) {
- if (Z_TYPE_P(zv) != IS_OBJECT) {
- return 0;
- }
- zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
- if (!called_scope) {
- return 0;
- }
- return instanceof_function(Z_OBJCE_P(zv), called_scope);
- }
- static zend_always_inline zend_bool zend_check_type_slow(
- zend_type type, zval *arg, zend_reference *ref, void **cache_slot, zend_class_entry *scope,
- zend_bool is_return_type, zend_bool is_internal)
- {
- uint32_t type_mask;
- if (ZEND_TYPE_HAS_CLASS(type) && Z_TYPE_P(arg) == IS_OBJECT) {
- zend_class_entry *ce;
- if (ZEND_TYPE_HAS_LIST(type)) {
- zend_type *list_type;
- ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(type), list_type) {
- if (*cache_slot) {
- ce = *cache_slot;
- } else {
- ce = zend_fetch_class(ZEND_TYPE_NAME(*list_type),
- (ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD));
- if (!ce) {
- cache_slot++;
- continue;
- }
- *cache_slot = ce;
- }
- if (instanceof_function(Z_OBJCE_P(arg), ce)) {
- return 1;
- }
- cache_slot++;
- } ZEND_TYPE_LIST_FOREACH_END();
- } else {
- if (EXPECTED(*cache_slot)) {
- ce = (zend_class_entry *) *cache_slot;
- } else {
- ce = zend_fetch_class(ZEND_TYPE_NAME(type), (ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD));
- if (UNEXPECTED(!ce)) {
- goto builtin_types;
- }
- *cache_slot = (void *) ce;
- }
- if (instanceof_function(Z_OBJCE_P(arg), ce)) {
- return 1;
- }
- }
- }
- builtin_types:
- type_mask = ZEND_TYPE_FULL_MASK(type);
- if ((type_mask & MAY_BE_CALLABLE) && zend_is_callable(arg, 0, NULL)) {
- return 1;
- }
- if ((type_mask & MAY_BE_ITERABLE) && zend_is_iterable(arg)) {
- return 1;
- }
- if ((type_mask & MAY_BE_STATIC) && zend_value_instanceof_static(arg)) {
- return 1;
- }
- if (ref && ZEND_REF_HAS_TYPE_SOURCES(ref)) {
- /* We cannot have conversions for typed refs. */
- return 0;
- }
- if (is_internal && is_return_type) {
- /* For internal returns, the type has to match exactly, because we're not
- * going to check it for non-debug builds, and there will be no chance to
- * apply coercions. */
- return 0;
- }
- return zend_verify_scalar_type_hint(type_mask, arg,
- is_return_type ? ZEND_RET_USES_STRICT_TYPES() : ZEND_ARG_USES_STRICT_TYPES(),
- is_internal);
- /* Special handling for IS_VOID is not necessary (for return types),
- * because this case is already checked at compile-time. */
- }
- static zend_always_inline zend_bool zend_check_type(
- zend_type type, zval *arg, void **cache_slot, zend_class_entry *scope,
- zend_bool is_return_type, zend_bool is_internal)
- {
- zend_reference *ref = NULL;
- ZEND_ASSERT(ZEND_TYPE_IS_SET(type));
- if (UNEXPECTED(Z_ISREF_P(arg))) {
- ref = Z_REF_P(arg);
- arg = Z_REFVAL_P(arg);
- }
- if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(type, Z_TYPE_P(arg)))) {
- return 1;
- }
- return zend_check_type_slow(type, arg, ref, cache_slot, scope, is_return_type, is_internal);
- }
- static zend_always_inline int zend_verify_recv_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, void **cache_slot)
- {
- zend_arg_info *cur_arg_info;
- ZEND_ASSERT(arg_num <= zf->common.num_args);
- cur_arg_info = &zf->common.arg_info[arg_num-1];
- if (ZEND_TYPE_IS_SET(cur_arg_info->type)
- && UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, cache_slot, zf->common.scope, 0, 0))) {
- zend_verify_arg_error(zf, cur_arg_info, arg_num, cache_slot, arg);
- return 0;
- }
- return 1;
- }
- static zend_always_inline int zend_verify_variadic_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, void **cache_slot)
- {
- zend_arg_info *cur_arg_info;
- ZEND_ASSERT(arg_num > zf->common.num_args);
- ZEND_ASSERT(zf->common.fn_flags & ZEND_ACC_VARIADIC);
- cur_arg_info = &zf->common.arg_info[zf->common.num_args];
- if (ZEND_TYPE_IS_SET(cur_arg_info->type)
- && UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, cache_slot, zf->common.scope, 0, 0))) {
- zend_verify_arg_error(zf, cur_arg_info, arg_num, cache_slot, arg);
- return 0;
- }
- return 1;
- }
- static zend_never_inline ZEND_ATTRIBUTE_UNUSED int zend_verify_internal_arg_types(zend_function *fbc, zend_execute_data *call)
- {
- uint32_t i;
- uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
- zval *arg = ZEND_CALL_ARG(call, 1);
- for (i = 0; i < num_args; ++i) {
- zend_arg_info *cur_arg_info;
- void *dummy_cache_slot = NULL;
- if (EXPECTED(i < fbc->common.num_args)) {
- cur_arg_info = &fbc->common.arg_info[i];
- } else if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) {
- cur_arg_info = &fbc->common.arg_info[fbc->common.num_args];
- } else {
- break;
- }
- if (ZEND_TYPE_IS_SET(cur_arg_info->type)
- && UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, &dummy_cache_slot, fbc->common.scope, 0, /* is_internal */ 1))) {
- return 0;
- }
- arg++;
- }
- return 1;
- }
- #if ZEND_DEBUG
- /* Determine whether an internal call should throw, because the passed arguments violate
- * an arginfo constraint. This is only checked in debug builds. In release builds, we
- * trust that arginfo matches what is enforced by zend_parse_parameters. */
- static zend_always_inline zend_bool zend_internal_call_should_throw(zend_function *fbc, zend_execute_data *call)
- {
- if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) {
- return 1;
- }
- if ((fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) &&
- !zend_verify_internal_arg_types(fbc, call)) {
- return 1;
- }
- return 0;
- }
- static ZEND_COLD void zend_internal_call_arginfo_violation(zend_function *fbc)
- {
- zend_error(E_CORE_ERROR, "Arginfo / zpp mismatch during call of %s%s%s()",
- fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "",
- fbc->common.scope ? "::" : "",
- ZSTR_VAL(fbc->common.function_name));
- }
- #endif
- ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(zend_execute_data *execute_data)
- {
- zend_execute_data *ptr = EX(prev_execute_data);
- if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
- zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed in %s on line %d and %s %d expected",
- EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "",
- EX(func)->common.scope ? "::" : "",
- ZSTR_VAL(EX(func)->common.function_name),
- EX_NUM_ARGS(),
- ZSTR_VAL(ptr->func->op_array.filename),
- ptr->opline->lineno,
- EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least",
- EX(func)->common.required_num_args);
- } else {
- zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed and %s %d expected",
- EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "",
- EX(func)->common.scope ? "::" : "",
- ZSTR_VAL(EX(func)->common.function_name),
- EX_NUM_ARGS(),
- EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least",
- EX(func)->common.required_num_args);
- }
- }
- ZEND_API ZEND_COLD void zend_verify_return_error(
- const zend_function *zf, void **cache_slot, zval *value)
- {
- const zend_arg_info *arg_info = &zf->common.arg_info[-1];
- const char *fname, *fsep, *fclass;
- zend_string *need_msg;
- const char *given_msg;
- zend_verify_type_error_common(
- zf, arg_info, cache_slot, value,
- &fname, &fsep, &fclass, &need_msg, &given_msg);
- zend_type_error("Return value of %s%s%s() must be of type %s, %s returned",
- fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg);
- zend_string_release(need_msg);
- }
- #if ZEND_DEBUG
- static ZEND_COLD void zend_verify_internal_return_error(
- const zend_function *zf, void **cache_slot, zval *value)
- {
- const zend_arg_info *arg_info = &zf->common.arg_info[-1];
- const char *fname, *fsep, *fclass;
- zend_string *need_msg;
- const char *given_msg;
- zend_verify_type_error_common(
- zf, arg_info, cache_slot, value,
- &fname, &fsep, &fclass, &need_msg, &given_msg);
- zend_error_noreturn(E_CORE_ERROR, "Return value of %s%s%s() must be of type %s, %s returned",
- fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg);
- }
- static ZEND_COLD void zend_verify_void_return_error(const zend_function *zf, const char *returned_msg, const char *returned_kind)
- {
- const char *fname = ZSTR_VAL(zf->common.function_name);
- const char *fsep;
- const char *fclass;
- if (zf->common.scope) {
- fsep = "::";
- fclass = ZSTR_VAL(zf->common.scope->name);
- } else {
- fsep = "";
- fclass = "";
- }
- zend_type_error("%s%s%s() must not return a value, %s%s returned",
- fclass, fsep, fname, returned_msg, returned_kind);
- }
- static int zend_verify_internal_return_type(zend_function *zf, zval *ret)
- {
- zend_internal_arg_info *ret_info = zf->internal_function.arg_info - 1;
- void *dummy_cache_slot = NULL;
- if (ZEND_TYPE_FULL_MASK(ret_info->type) & MAY_BE_VOID) {
- if (UNEXPECTED(Z_TYPE_P(ret) != IS_NULL)) {
- zend_verify_void_return_error(zf, zend_zval_type_name(ret), "");
- return 0;
- }
- return 1;
- }
- if (UNEXPECTED(!zend_check_type(ret_info->type, ret, &dummy_cache_slot, NULL, 1, /* is_internal */ 1))) {
- zend_verify_internal_return_error(zf, &dummy_cache_slot, ret);
- return 0;
- }
- return 1;
- }
- #endif
- static ZEND_COLD int zend_verify_missing_return_type(const zend_function *zf, void **cache_slot)
- {
- /* VERIFY_RETURN_TYPE is not emitted for "void" functions, so this is always an error. */
- zend_verify_return_error(zf, cache_slot, NULL);
- return 0;
- }
- static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(void)
- {
- zend_throw_error(NULL, "Cannot use object as array");
- }
- static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(void)
- {
- zend_type_error("Illegal offset type");
- }
- static zend_never_inline void zend_assign_to_object_dim(zval *object, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)
- {
- Z_OBJ_HT_P(object)->write_dimension(Z_OBJ_P(object), dim, value);
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_COPY(EX_VAR(opline->result.var), value);
- }
- }
- static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPLINE_DC)
- {
- static const binary_op_type zend_binary_ops[] = {
- add_function,
- sub_function,
- mul_function,
- div_function,
- mod_function,
- shift_left_function,
- shift_right_function,
- concat_function,
- bitwise_or_function,
- bitwise_and_function,
- bitwise_xor_function,
- pow_function
- };
- /* size_t cast makes GCC to better optimize 64-bit PIC code */
- size_t opcode = (size_t)opline->extended_value;
- return zend_binary_ops[opcode - ZEND_ADD](ret, op1, op2);
- }
- static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *property OPLINE_DC EXECUTE_DATA_DC)
- {
- zval *value;
- zval *z;
- zval rv, res;
- value = get_op_data_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1);
- if ((z = Z_OBJ_HT_P(object)->read_dimension(Z_OBJ_P(object), property, BP_VAR_R, &rv)) != NULL) {
- if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) {
- Z_OBJ_HT_P(object)->write_dimension(Z_OBJ_P(object), property, &res);
- }
- if (z == &rv) {
- zval_ptr_dtor(&rv);
- }
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_COPY(EX_VAR(opline->result.var), &res);
- }
- zval_ptr_dtor(&res);
- } else {
- zend_use_object_as_array();
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- }
- FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
- }
- static zend_never_inline void zend_binary_assign_op_typed_ref(zend_reference *ref, zval *value OPLINE_DC EXECUTE_DATA_DC)
- {
- zval z_copy;
- zend_binary_op(&z_copy, &ref->val, value OPLINE_CC);
- if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(&ref->val);
- ZVAL_COPY_VALUE(&ref->val, &z_copy);
- } else {
- zval_ptr_dtor(&z_copy);
- }
- }
- static zend_never_inline void zend_binary_assign_op_typed_prop(zend_property_info *prop_info, zval *zptr, zval *value OPLINE_DC EXECUTE_DATA_DC)
- {
- zval z_copy;
- zend_binary_op(&z_copy, zptr, value OPLINE_CC);
- if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) {
- zval_ptr_dtor(zptr);
- ZVAL_COPY_VALUE(zptr, &z_copy);
- } else {
- zval_ptr_dtor(&z_copy);
- }
- }
- static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type EXECUTE_DATA_DC)
- {
- zend_long offset;
- try_again:
- if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
- switch(Z_TYPE_P(dim)) {
- case IS_STRING:
- if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, -1)) {
- break;
- }
- if (type != BP_VAR_UNSET) {
- zend_error(E_WARNING, "Illegal string offset '%s'", Z_STRVAL_P(dim));
- }
- break;
- case IS_UNDEF:
- ZVAL_UNDEFINED_OP2();
- case IS_DOUBLE:
- case IS_NULL:
- case IS_FALSE:
- case IS_TRUE:
- zend_error(E_WARNING, "String offset cast occurred");
- break;
- case IS_REFERENCE:
- dim = Z_REFVAL_P(dim);
- goto try_again;
- default:
- zend_illegal_offset();
- break;
- }
- offset = zval_get_long_func(dim);
- } else {
- offset = Z_LVAL_P(dim);
- }
- return offset;
- }
- static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
- {
- const char *msg = NULL;
- const zend_op *opline = EX(opline);
- const zend_op *end;
- uint32_t var;
- if (UNEXPECTED(EG(exception) != NULL)) {
- return;
- }
- switch (opline->opcode) {
- case ZEND_ASSIGN_OP:
- case ZEND_ASSIGN_DIM_OP:
- case ZEND_ASSIGN_OBJ_OP:
- case ZEND_ASSIGN_STATIC_PROP_OP:
- msg = "Cannot use assign-op operators with string offsets";
- break;
- case ZEND_FETCH_DIM_W:
- case ZEND_FETCH_DIM_RW:
- case ZEND_FETCH_DIM_FUNC_ARG:
- case ZEND_FETCH_DIM_UNSET:
- case ZEND_FETCH_LIST_W:
- /* TODO: Encode the "reason" into opline->extended_value??? */
- var = opline->result.var;
- opline++;
- end = EG(current_execute_data)->func->op_array.opcodes +
- EG(current_execute_data)->func->op_array.last;
- while (opline < end) {
- if (opline->op1_type == IS_VAR && opline->op1.var == var) {
- switch (opline->opcode) {
- case ZEND_ASSIGN_OBJ_OP:
- msg = "Cannot use string offset as an object";
- break;
- case ZEND_ASSIGN_DIM_OP:
- msg = "Cannot use string offset as an array";
- break;
- case ZEND_ASSIGN_STATIC_PROP_OP:
- case ZEND_ASSIGN_OP:
- msg = "Cannot use assign-op operators with string offsets";
- break;
- case ZEND_PRE_INC_OBJ:
- case ZEND_PRE_DEC_OBJ:
- case ZEND_POST_INC_OBJ:
- case ZEND_POST_DEC_OBJ:
- case ZEND_PRE_INC:
- case ZEND_PRE_DEC:
- case ZEND_POST_INC:
- case ZEND_POST_DEC:
- msg = "Cannot increment/decrement string offsets";
- break;
- case ZEND_FETCH_DIM_W:
- case ZEND_FETCH_DIM_RW:
- case ZEND_FETCH_DIM_FUNC_ARG:
- case ZEND_FETCH_DIM_UNSET:
- case ZEND_FETCH_LIST_W:
- case ZEND_ASSIGN_DIM:
- msg = "Cannot use string offset as an array";
- break;
- case ZEND_FETCH_OBJ_W:
- case ZEND_FETCH_OBJ_RW:
- case ZEND_FETCH_OBJ_FUNC_ARG:
- case ZEND_FETCH_OBJ_UNSET:
- case ZEND_ASSIGN_OBJ:
- msg = "Cannot use string offset as an object";
- break;
- case ZEND_ASSIGN_REF:
- case ZEND_ADD_ARRAY_ELEMENT:
- case ZEND_INIT_ARRAY:
- case ZEND_MAKE_REF:
- msg = "Cannot create references to/from string offsets";
- break;
- case ZEND_RETURN_BY_REF:
- case ZEND_VERIFY_RETURN_TYPE:
- msg = "Cannot return string offsets by reference";
- break;
- case ZEND_UNSET_DIM:
- case ZEND_UNSET_OBJ:
- msg = "Cannot unset string offsets";
- break;
- case ZEND_YIELD:
- msg = "Cannot yield string offsets by reference";
- break;
- case ZEND_SEND_REF:
- case ZEND_SEND_VAR_EX:
- case ZEND_SEND_FUNC_ARG:
- msg = "Only variables can be passed by reference";
- break;
- case ZEND_FE_RESET_RW:
- msg = "Cannot iterate on string offsets by reference";
- break;
- EMPTY_SWITCH_DEFAULT_CASE();
- }
- break;
- }
- if (opline->op2_type == IS_VAR && opline->op2.var == var) {
- ZEND_ASSERT(opline->opcode == ZEND_ASSIGN_REF);
- msg = "Cannot create references to/from string offsets";
- break;
- }
- }
- break;
- EMPTY_SWITCH_DEFAULT_CASE();
- }
- ZEND_ASSERT(msg != NULL);
- zend_throw_error(NULL, "%s", msg);
- }
- static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(zval *property)
- {
- zend_string *tmp_property_name;
- zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
- zend_error(E_WARNING, "Trying to get property '%s' of non-object", ZSTR_VAL(property_name));
- zend_tmp_string_release(tmp_property_name);
- }
- static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc)
- {
- zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
- fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "",
- fbc->common.scope ? "::" : "",
- ZSTR_VAL(fbc->common.function_name));
- }
- static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)
- {
- zend_uchar c;
- size_t string_len;
- zend_long offset;
- offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC);
- if (offset < -(zend_long)Z_STRLEN_P(str)) {
- /* Error on negative offset */
- zend_error(E_WARNING, "Illegal string offset: " ZEND_LONG_FMT, offset);
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- return;
- }
- if (Z_TYPE_P(value) != IS_STRING) {
- /* Convert to string, just the time to pick the 1st byte */
- zend_string *tmp = zval_try_get_string_func(value);
- if (UNEXPECTED(!tmp)) {
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return;
- }
- string_len = ZSTR_LEN(tmp);
- c = (zend_uchar)ZSTR_VAL(tmp)[0];
- zend_string_release_ex(tmp, 0);
- } else {
- string_len = Z_STRLEN_P(value);
- c = (zend_uchar)Z_STRVAL_P(value)[0];
- }
- if (string_len != 1) {
- if (string_len == 0) {
- /* Error on empty input string */
- zend_throw_error(NULL, "Cannot assign an empty string to a string offset");
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- return;
- }
- zend_error(E_WARNING, "Only the first byte will be assigned to the string offset");
- }
- if (offset < 0) { /* Handle negative offset */
- offset += (zend_long)Z_STRLEN_P(str);
- }
- if ((size_t)offset >= Z_STRLEN_P(str)) {
- /* Extend string if needed */
- zend_long old_len = Z_STRLEN_P(str);
- ZVAL_NEW_STR(str, zend_string_extend(Z_STR_P(str), offset + 1, 0));
- memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
- Z_STRVAL_P(str)[offset+1] = 0;
- } else if (!Z_REFCOUNTED_P(str)) {
- ZVAL_NEW_STR(str, zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0));
- } else if (Z_REFCOUNT_P(str) > 1) {
- Z_DELREF_P(str);
- ZVAL_NEW_STR(str, zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0));
- } else {
- zend_string_forget_hash_val(Z_STR_P(str));
- }
- Z_STRVAL_P(str)[offset] = c;
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- /* Return the new character */
- ZVAL_INTERNED_STR(EX_VAR(opline->result.var), ZSTR_CHAR(c));
- }
- }
- static zend_property_info *zend_get_prop_not_accepting_double(zend_reference *ref)
- {
- zend_property_info *prop;
- ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
- if (!(ZEND_TYPE_FULL_MASK(prop->type) & MAY_BE_DOUBLE)) {
- return prop;
- }
- } ZEND_REF_FOREACH_TYPE_SOURCES_END();
- return NULL;
- }
- static ZEND_COLD zend_long zend_throw_incdec_ref_error(
- zend_reference *ref, zend_property_info *error_prop OPLINE_DC)
- {
- zend_string *type_str = zend_type_to_string(error_prop->type);
- if (ZEND_IS_INCREMENT(opline->opcode)) {
- zend_type_error(
- "Cannot increment a reference held by property %s::$%s of type %s past its maximal value",
- ZSTR_VAL(error_prop->ce->name),
- zend_get_unmangled_property_name(error_prop->name),
- ZSTR_VAL(type_str));
- zend_string_release(type_str);
- return ZEND_LONG_MAX;
- } else {
- zend_type_error(
- "Cannot decrement a reference held by property %s::$%…
Large files files are truncated, but you can click here to view the full file