summaryrefslogtreecommitdiff
path: root/Zend/zend_execute.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_execute.c')
-rw-r--r--Zend/zend_execute.c1168
1 files changed, 455 insertions, 713 deletions
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 5407d89680..673840ace5 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -109,16 +109,16 @@
typedef int (ZEND_FASTCALL *incdec_t)(zval *);
-#define get_zval_ptr(op_type, node, should_free, type) _get_zval_ptr(op_type, node, should_free, type EXECUTE_DATA_CC OPLINE_CC)
-#define get_zval_ptr_deref(op_type, node, should_free, type) _get_zval_ptr_deref(op_type, node, should_free, type EXECUTE_DATA_CC OPLINE_CC)
-#define get_zval_ptr_undef(op_type, node, should_free, type) _get_zval_ptr_undef(op_type, node, should_free, type EXECUTE_DATA_CC OPLINE_CC)
-#define get_op_data_zval_ptr_r(op_type, node, should_free) _get_op_data_zval_ptr_r(op_type, node, should_free EXECUTE_DATA_CC OPLINE_CC)
-#define get_op_data_zval_ptr_deref_r(op_type, node, should_free) _get_op_data_zval_ptr_deref_r(op_type, node, should_free EXECUTE_DATA_CC OPLINE_CC)
-#define get_zval_ptr_ptr(op_type, node, should_free, type) _get_zval_ptr_ptr(op_type, node, should_free, type EXECUTE_DATA_CC)
-#define get_zval_ptr_ptr_undef(op_type, node, should_free, type) _get_zval_ptr_ptr(op_type, node, should_free, type EXECUTE_DATA_CC)
-#define get_obj_zval_ptr(op_type, node, should_free, type) _get_obj_zval_ptr(op_type, node, should_free, type EXECUTE_DATA_CC OPLINE_CC)
-#define get_obj_zval_ptr_undef(op_type, node, should_free, type) _get_obj_zval_ptr_undef(op_type, node, should_free, type EXECUTE_DATA_CC OPLINE_CC)
-#define get_obj_zval_ptr_ptr(op_type, node, should_free, type) _get_obj_zval_ptr_ptr(op_type, node, should_free, type EXECUTE_DATA_CC)
+#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)
@@ -141,13 +141,12 @@ ZEND_API const zend_internal_function zend_pass_function = {
{NULL,NULL,NULL,NULL} /* reserved */
};
-#define FREE_VAR_PTR_AND_EXTRACT_RESULT_IF_NECESSARY(free_op, result) do { \
- zval *__container_to_free = (free_op); \
- if (UNEXPECTED(__container_to_free) \
- && EXPECTED(Z_REFCOUNTED_P(__container_to_free))) { \
+#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 = (result); \
+ zval *__zv = EX_VAR(opline->result.var); \
if (EXPECTED(Z_TYPE_P(__zv) == IS_INDIRECT)) { \
ZVAL_COPY(__zv, Z_INDIRECT_P(__zv)); \
} \
@@ -156,20 +155,16 @@ ZEND_API const zend_internal_function zend_pass_function = {
} \
} while (0)
-#define FREE_OP(should_free) \
- if (should_free) { \
- zval_ptr_dtor_nogc(should_free); \
- }
-
-#define FREE_UNFETCHED_OP(type, var) \
+#define FREE_OP(type, var) \
if ((type) & (IS_TMP_VAR|IS_VAR)) { \
zval_ptr_dtor_nogc(EX_VAR(var)); \
}
-#define FREE_OP_VAR_PTR(should_free) \
- if (should_free) { \
- zval_ptr_dtor_nogc(should_free); \
- }
+#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])
@@ -241,29 +236,26 @@ ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute
return EX_VAR(var);
}
-static zend_always_inline zval *_get_zval_ptr_tmp(uint32_t var, zend_free_op *should_free EXECUTE_DATA_DC)
+static zend_always_inline zval *_get_zval_ptr_tmp(uint32_t var EXECUTE_DATA_DC)
{
zval *ret = EX_VAR(var);
- *should_free = ret;
ZEND_ASSERT(Z_TYPE_P(ret) != IS_REFERENCE);
return ret;
}
-static zend_always_inline zval *_get_zval_ptr_var(uint32_t var, zend_free_op *should_free EXECUTE_DATA_DC)
+static zend_always_inline zval *_get_zval_ptr_var(uint32_t var EXECUTE_DATA_DC)
{
zval *ret = EX_VAR(var);
- *should_free = ret;
return ret;
}
-static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var, zend_free_op *should_free EXECUTE_DATA_DC)
+static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var EXECUTE_DATA_DC)
{
zval *ret = EX_VAR(var);
- *should_free = ret;
ZVAL_DEREF(ret);
return ret;
}
@@ -272,7 +264,7 @@ static zend_never_inline ZEND_COLD zval* zval_undefined_cv(uint32_t var EXECUTE_
{
if (EXPECTED(EG(exception) == NULL)) {
zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
- zend_error(E_NOTICE, "Undefined variable: %s", ZSTR_VAL(cv));
+ zend_error(E_WARNING, "Undefined variable: %s", ZSTR_VAL(cv));
}
return &EG(uninitialized_zval);
}
@@ -390,17 +382,16 @@ static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_W(uint32_t var EXECUTE_D
return ret;
}
-static zend_always_inline zval *_get_zval_ptr(int op_type, znode_op node, zend_free_op *should_free, int type EXECUTE_DATA_DC OPLINE_DC)
+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, should_free EXECUTE_DATA_CC);
+ 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, should_free EXECUTE_DATA_CC);
+ return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
}
} else {
- *should_free = NULL;
if (op_type == IS_CONST) {
return RT_CONSTANT(opline, node);
} else if (op_type == IS_CV) {
@@ -411,17 +402,16 @@ static zend_always_inline zval *_get_zval_ptr(int op_type, znode_op node, zend_f
}
}
-static zend_always_inline zval *_get_op_data_zval_ptr_r(int op_type, znode_op node, zend_free_op *should_free EXECUTE_DATA_DC OPLINE_DC)
+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, should_free EXECUTE_DATA_CC);
+ 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, should_free EXECUTE_DATA_CC);
+ return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
}
} else {
- *should_free = NULL;
if (op_type == IS_CONST) {
return RT_CONSTANT(opline + 1, node);
} else if (op_type == IS_CV) {
@@ -432,17 +422,16 @@ static zend_always_inline zval *_get_op_data_zval_ptr_r(int op_type, znode_op no
}
}
-static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_zval_ptr_deref(int op_type, znode_op node, zend_free_op *should_free, int type EXECUTE_DATA_DC OPLINE_DC)
+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, should_free EXECUTE_DATA_CC);
+ 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, should_free EXECUTE_DATA_CC);
+ return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
}
} else {
- *should_free = NULL;
if (op_type == IS_CONST) {
return RT_CONSTANT(opline, node);
} else if (op_type == IS_CV) {
@@ -453,17 +442,16 @@ static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_zval_ptr_deref(int op
}
}
-static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_op_data_zval_ptr_deref_r(int op_type, znode_op node, zend_free_op *should_free EXECUTE_DATA_DC OPLINE_DC)
+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, should_free EXECUTE_DATA_CC);
+ 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, should_free EXECUTE_DATA_CC);
+ return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
}
} else {
- *should_free = NULL;
if (op_type == IS_CONST) {
return RT_CONSTANT(opline + 1, node);
} else if (op_type == IS_CV) {
@@ -474,17 +462,16 @@ static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_op_data_zval_ptr_dere
}
}
-static zend_always_inline zval *_get_zval_ptr_undef(int op_type, znode_op node, zend_free_op *should_free, int type EXECUTE_DATA_DC OPLINE_DC)
+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, should_free EXECUTE_DATA_CC);
+ 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, should_free EXECUTE_DATA_CC);
+ return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
}
} else {
- *should_free = NULL;
if (op_type == IS_CONST) {
return RT_CONSTANT(opline, node);
} else if (op_type == IS_CV) {
@@ -495,55 +482,48 @@ static zend_always_inline zval *_get_zval_ptr_undef(int op_type, znode_op node,
}
}
-static zend_always_inline zval *_get_zval_ptr_ptr_var(uint32_t var, zend_free_op *should_free EXECUTE_DATA_DC)
+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)) {
- *should_free = NULL;
ret = Z_INDIRECT_P(ret);
- } else {
- *should_free = ret;
}
return ret;
}
-static inline zval *_get_zval_ptr_ptr(int op_type, znode_op node, zend_free_op *should_free, int type EXECUTE_DATA_DC)
+static inline zval *_get_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC)
{
if (op_type == IS_CV) {
- *should_free = NULL;
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, should_free EXECUTE_DATA_CC);
+ 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, zend_free_op *should_free, int type EXECUTE_DATA_DC OPLINE_DC)
+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) {
- *should_free = NULL;
return &EX(This);
}
- return get_zval_ptr(op_type, op, should_free, type);
+ 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, zend_free_op *should_free, int type EXECUTE_DATA_DC OPLINE_DC)
+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) {
- *should_free = NULL;
return &EX(This);
}
- return get_zval_ptr_undef(op_type, op, should_free, type);
+ 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, zend_free_op *should_free, int type EXECUTE_DATA_DC)
+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) {
- *should_free = NULL;
return &EX(This);
}
- return get_zval_ptr_ptr(op_type, node, should_free, type);
+ return get_zval_ptr_ptr(op_type, node, type);
}
static inline void zend_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr)
@@ -602,39 +582,26 @@ static zend_never_inline ZEND_COLD int zend_wrong_assign_to_variable_reference(z
return 1;
}
-static void zend_format_type(zend_type type, const char **part1, const char **part2) {
- *part1 = ZEND_TYPE_ALLOW_NULL(type) ? "?" : "";
- if (ZEND_TYPE_IS_CLASS(type)) {
- if (ZEND_TYPE_IS_CE(type)) {
- *part2 = ZSTR_VAL(ZEND_TYPE_CE(type)->name);
- } else {
- *part2 = ZSTR_VAL(ZEND_TYPE_NAME(type));
- }
- } else {
- *part2 = zend_get_type_by_const(ZEND_TYPE_CODE(type));
- }
-}
-
static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(zend_property_info *prop, const char *type) {
- const char *prop_type1, *prop_type2;
- zend_format_type(prop->type, &prop_type1, &prop_type2);
+ 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%s",
+ "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),
- prop_type1, prop_type2
+ 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) {
- const char *prop_type1, *prop_type2;
- zend_format_type(prop->type, &prop_type1, &prop_type2);
+ 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%s",
+ "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),
- prop_type1, prop_type2
+ ZSTR_VAL(type_str)
);
+ zend_string_release(type_str);
}
static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_error(
@@ -645,75 +612,39 @@ static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_err
zend_get_unmangled_property_name(prop->name));
}
-static zend_never_inline zend_bool zend_verify_ref_stdClass_assignable(zend_reference *ref);
-static zend_never_inline zend_bool zend_verify_ref_array_assignable(zend_reference *ref);
-
/* this should modify object only if it's empty */
-static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL make_real_object(zval *object, zval *property OPLINE_DC EXECUTE_DATA_DC)
-{
- zend_object *obj;
- zval *ref = NULL;
- if (Z_ISREF_P(object)) {
- ref = object;
- object = Z_REFVAL_P(object);
- }
-
- if (UNEXPECTED(Z_TYPE_P(object) > IS_FALSE &&
- (Z_TYPE_P(object) != IS_STRING || Z_STRLEN_P(object) != 0))) {
- if (opline->op1_type != IS_VAR || EXPECTED(!Z_ISERROR_P(object))) {
- 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_error(E_WARNING, "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_error(E_WARNING, "Attempt to modify property '%s' of non-object", ZSTR_VAL(property_name));
- } else {
- zend_error(E_WARNING, "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));
- }
- return NULL;
- }
+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 (ref && ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(ref))) {
- if (UNEXPECTED(!zend_verify_ref_stdClass_assignable(Z_REF_P(ref)))) {
- if (RETURN_VALUE_USED(opline)) {
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
- return NULL;
- }
+ 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);
- zval_ptr_dtor_nogc(object);
- object_init(object);
- Z_ADDREF_P(object);
- obj = Z_OBJ_P(object);
- zend_error(E_WARNING, "Creating default object from empty value");
- if (GC_REFCOUNT(obj) == 1) {
- /* the enclosing container was deleted, obj is unreferenced */
- OBJ_RELEASE(obj);
- if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
- ZVAL_NULL(EX_VAR(opline->result.var));
- }
- return NULL;
+ if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
+ ZVAL_NULL(EX_VAR(opline->result.var));
}
- Z_DELREF_P(object);
- return object;
}
static ZEND_COLD void zend_verify_type_error_common(
const zend_function *zf, const zend_arg_info *arg_info,
- const zend_class_entry *ce, zval *value,
+ void **cache_slot, zval *value,
const char **fname, const char **fsep, const char **fclass,
const char **need_msg, const char **need_kind, const char **need_or_null,
const char **given_msg, const char **given_kind)
@@ -729,6 +660,7 @@ static ZEND_COLD void zend_verify_type_error_common(
}
if (ZEND_TYPE_IS_CLASS(arg_info->type)) {
+ zend_class_entry *ce = *cache_slot;
if (ce) {
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
*need_msg = "implement interface ";
@@ -744,22 +676,25 @@ static ZEND_COLD void zend_verify_type_error_common(
*need_kind = ZSTR_VAL(ZEND_TYPE_NAME(arg_info->type));
}
} else {
- switch (ZEND_TYPE_CODE(arg_info->type)) {
- case IS_OBJECT:
+ zend_type type = ZEND_TYPE_WITHOUT_NULL(arg_info->type);
+ switch (ZEND_TYPE_MASK(type)) {
+ case MAY_BE_OBJECT:
*need_msg = "be an ";
*need_kind = "object";
break;
- case IS_CALLABLE:
+ case MAY_BE_CALLABLE:
*need_msg = "be callable";
*need_kind = "";
break;
- case IS_ITERABLE:
+ case MAY_BE_ITERABLE:
*need_msg = "be iterable";
*need_kind = "";
break;
default:
+ /* TODO: The zend_type_to_string() result is guaranteed interned here.
+ * It would be beter to switch all this code to use zend_string though. */
*need_msg = "be of the type ";
- *need_kind = zend_get_type_by_const(ZEND_TYPE_CODE(arg_info->type));
+ *need_kind = ZSTR_VAL(zend_type_to_string(type));
break;
}
}
@@ -784,9 +719,9 @@ static ZEND_COLD void zend_verify_type_error_common(
}
}
-static ZEND_COLD void zend_verify_arg_error(
+ZEND_API ZEND_COLD void zend_verify_arg_error(
const zend_function *zf, const zend_arg_info *arg_info,
- int arg_num, const zend_class_entry *ce, zval *value)
+ int arg_num, void **cache_slot, zval *value)
{
zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
const char *fname, *fsep, *fclass;
@@ -800,7 +735,7 @@ static ZEND_COLD void zend_verify_arg_error(
if (value) {
zend_verify_type_error_common(
- zf, arg_info, ce, value,
+ zf, arg_info, cache_slot, value,
&fname, &fsep, &fclass, &need_msg, &need_kind, &need_or_null, &given_msg, &given_kind);
if (zf->common.type == ZEND_USER_FUNCTION) {
@@ -819,108 +754,129 @@ static ZEND_COLD void zend_verify_arg_error(
}
}
-static int is_null_constant(zend_class_entry *scope, zval *default_value)
+static zend_bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg)
{
- if (Z_TYPE_P(default_value) == IS_CONSTANT_AST) {
- zval constant;
+ if (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE)) {
+ zend_bool dest;
- ZVAL_COPY(&constant, default_value);
- if (UNEXPECTED(zval_update_constant_ex(&constant, scope) != SUCCESS)) {
+ if (!zend_parse_arg_bool_weak(arg, &dest)) {
return 0;
}
- if (Z_TYPE(constant) == IS_NULL) {
- return 1;
- }
- zval_ptr_dtor_nogc(&constant);
+ zval_ptr_dtor(arg);
+ ZVAL_BOOL(arg, dest);
+ return 1;
}
- return 0;
-}
+ if (type_mask & MAY_BE_LONG) {
+ zend_long dest;
-static zend_bool zend_verify_weak_scalar_type_hint(zend_uchar type_hint, zval *arg)
-{
- switch (type_hint) {
- case _IS_BOOL: {
- zend_bool dest;
+ if (!zend_parse_arg_long_weak(arg, &dest)) {
+ return 0;
+ }
+ zval_ptr_dtor(arg);
+ ZVAL_LONG(arg, dest);
+ return 1;
+ }
+ if (type_mask & MAY_BE_DOUBLE) {
+ double dest;
- if (!zend_parse_arg_bool_weak(arg, &dest)) {
- return 0;
- }
- zval_ptr_dtor(arg);
- ZVAL_BOOL(arg, dest);
- return 1;
+ if (!zend_parse_arg_double_weak(arg, &dest)) {
+ return 0;
}
- case IS_LONG: {
- zend_long dest;
+ zval_ptr_dtor(arg);
+ ZVAL_DOUBLE(arg, dest);
+ return 1;
+ }
+ if (type_mask & MAY_BE_STRING) {
+ zend_string *dest;
- if (!zend_parse_arg_long_weak(arg, &dest)) {
- return 0;
+ /* on success "arg" is converted to IS_STRING */
+ return zend_parse_arg_str_weak(arg, &dest);
+ }
+ 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)
+{
+ if (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE)) {
+ zend_bool dest;
+ return zend_parse_arg_bool_weak(arg, &dest);
+ }
+ if (type_mask & MAY_BE_LONG) {
+ zend_long dest;
+ if (Z_TYPE_P(arg) == IS_STRING) {
+ /* Handle this case separately to avoid the "non well-formed" warning */
+ double dval;
+ zend_uchar type = is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), NULL, &dval, 1);
+ if (type == IS_LONG) {
+ return 1;
}
- zval_ptr_dtor(arg);
- ZVAL_LONG(arg, dest);
- return 1;
- }
- case IS_DOUBLE: {
- double dest;
+ if (type == IS_DOUBLE) {
+ return !zend_isnan(dval) && ZEND_DOUBLE_FITS_LONG(dval);
- if (!zend_parse_arg_double_weak(arg, &dest)) {
- return 0;
}
- zval_ptr_dtor(arg);
- ZVAL_DOUBLE(arg, dest);
- return 1;
+ return 0;
}
- case IS_STRING: {
- zend_string *dest;
-
- /* on success "arg" is converted to IS_STRING */
- return zend_parse_arg_str_weak(arg, &dest);
+ return zend_parse_arg_long_weak(arg, &dest);
+ }
+ if (type_mask & MAY_BE_DOUBLE) {
+ double dest;
+ if (Z_TYPE_P(arg) == IS_STRING) {
+ /* Handle this case separately to avoid the "non well-formed" warning */
+ return is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), NULL, NULL, 1) != 0;
}
- default:
- return 0;
+ return zend_parse_arg_double_weak(arg, &dest);
+ }
+ if (type_mask & MAY_BE_STRING) {
+ /* 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. */
+ return Z_TYPE_P(arg) < IS_STRING || Z_TYPE_P(arg) == IS_OBJECT;
}
+ return 0;
}
+#endif
-static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg, zend_bool strict)
+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_hint != IS_DOUBLE || Z_TYPE_P(arg) != IS_LONG) {
+ 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) */
+ if (is_internal_arg && (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING))) {
+ /* As an exception, null is allowed for scalar types in weak mode. */
+ return 1;
+ }
return 0;
}
- return zend_verify_weak_scalar_type_hint(type_hint, arg);
+#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)
{
- const char *prop_type1, *prop_type2;
+ 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;
}
- // TODO Switch to a more standard error message?
- zend_format_type(info->type, &prop_type1, &prop_type2);
- (void) prop_type1;
- if (ZEND_TYPE_IS_CLASS(info->type)) {
- zend_type_error("Typed property %s::$%s must be an instance of %s%s, %s used",
- ZSTR_VAL(info->ce->name),
- zend_get_unmangled_property_name(info->name),
- prop_type2,
- ZEND_TYPE_ALLOW_NULL(info->type) ? " or null" : "",
- Z_TYPE_P(property) == IS_OBJECT ? ZSTR_VAL(Z_OBJCE_P(property)->name) : zend_get_type_by_const(Z_TYPE_P(property)));
- } else {
- zend_type_error("Typed property %s::$%s must be %s%s, %s used",
- ZSTR_VAL(info->ce->name),
- zend_get_unmangled_property_name(info->name),
- prop_type2,
- ZEND_TYPE_ALLOW_NULL(info->type) ? " or null" : "",
- Z_TYPE_P(property) == IS_OBJECT ? ZSTR_VAL(Z_OBJCE_P(property)->name) : zend_get_type_by_const(Z_TYPE_P(property)));
- }
+ 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_bool zend_resolve_class_type(zend_type *type, zend_class_entry *self_ce) {
@@ -968,17 +924,13 @@ static zend_always_inline zend_bool i_zend_check_property_type(zend_property_inf
return instanceof_function(Z_OBJCE_P(property), ZEND_TYPE_CE(info->type));
}
- ZEND_ASSERT(ZEND_TYPE_CODE(info->type) != IS_CALLABLE);
- if (EXPECTED(ZEND_TYPE_CODE(info->type) == Z_TYPE_P(property))) {
- return 1;
- } else if (EXPECTED(Z_TYPE_P(property) == IS_NULL)) {
- return ZEND_TYPE_ALLOW_NULL(info->type);
- } else if (ZEND_TYPE_CODE(info->type) == _IS_BOOL && EXPECTED(Z_TYPE_P(property) == IS_FALSE || Z_TYPE_P(property) == IS_TRUE)) {
+ ZEND_ASSERT(!(ZEND_TYPE_MASK(info->type) & MAY_BE_CALLABLE));
+ if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(info->type, Z_TYPE_P(property)))) {
return 1;
- } else if (ZEND_TYPE_CODE(info->type) == IS_ITERABLE) {
+ } else if (ZEND_TYPE_MASK(info->type) & MAY_BE_ITERABLE) {
return zend_is_iterable(property);
} else {
- return zend_verify_scalar_type_hint(ZEND_TYPE_CODE(info->type), property, strict);
+ return zend_verify_scalar_type_hint(ZEND_TYPE_MASK(info->type), property, strict, 0);
}
}
@@ -1013,16 +965,12 @@ static zend_never_inline zval* zend_assign_to_typed_prop(zend_property_info *inf
static zend_always_inline zend_bool zend_check_type(
- zend_type type,
- zval *arg, zend_class_entry **ce, void **cache_slot,
- zval *default_value, zend_class_entry *scope,
- zend_bool is_return_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;
-
- if (!ZEND_TYPE_IS_SET(type)) {
- return 1;
- }
+ uint32_t type_mask;
+ ZEND_ASSERT(ZEND_TYPE_IS_SET(type));
if (UNEXPECTED(Z_ISREF_P(arg))) {
ref = Z_REF_P(arg);
@@ -1030,121 +978,133 @@ static zend_always_inline zend_bool zend_check_type(
}
if (ZEND_TYPE_IS_CLASS(type)) {
+ zend_class_entry *ce;
if (EXPECTED(*cache_slot)) {
- *ce = (zend_class_entry *) *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)) {
- return Z_TYPE_P(arg) == IS_NULL && (ZEND_TYPE_ALLOW_NULL(type) || (default_value && is_null_constant(scope, default_value)));
+ ce = zend_fetch_class(ZEND_TYPE_NAME(type), (ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD));
+ if (UNEXPECTED(!ce)) {
+ return Z_TYPE_P(arg) == IS_NULL && ZEND_TYPE_ALLOW_NULL(type);
}
- *cache_slot = (void *) *ce;
+ *cache_slot = (void *) ce;
}
if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
- return instanceof_function(Z_OBJCE_P(arg), *ce);
+ return instanceof_function(Z_OBJCE_P(arg), ce);
}
- return Z_TYPE_P(arg) == IS_NULL && (ZEND_TYPE_ALLOW_NULL(type) || (default_value && is_null_constant(scope, default_value)));
- } else if (EXPECTED(ZEND_TYPE_CODE(type) == Z_TYPE_P(arg))) {
- return 1;
- }
-
- if (Z_TYPE_P(arg) == IS_NULL && (ZEND_TYPE_ALLOW_NULL(type) || (default_value && is_null_constant(scope, default_value)))) {
- /* Null passed to nullable type */
+ return Z_TYPE_P(arg) == IS_NULL && ZEND_TYPE_ALLOW_NULL(type);
+ } else if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(type, Z_TYPE_P(arg)))) {
return 1;
}
- if (ZEND_TYPE_CODE(type) == IS_CALLABLE) {
+ type_mask = ZEND_TYPE_MASK(type);
+ if (type_mask & MAY_BE_CALLABLE) {
return zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL);
- } else if (ZEND_TYPE_CODE(type) == IS_ITERABLE) {
+ } else if (type_mask & MAY_BE_ITERABLE) {
return zend_is_iterable(arg);
- } else if (ZEND_TYPE_CODE(type) == _IS_BOOL &&
- EXPECTED(Z_TYPE_P(arg) == IS_FALSE || Z_TYPE_P(arg) == IS_TRUE)) {
- return 1;
} else if (ref && ZEND_REF_HAS_TYPE_SOURCES(ref)) {
return 0; /* we cannot have conversions for typed refs */
+ } else 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;
} else {
- return zend_verify_scalar_type_hint(ZEND_TYPE_CODE(type), arg,
- is_return_type ? ZEND_RET_USES_STRICT_TYPES() : ZEND_ARG_USES_STRICT_TYPES());
+ 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 int zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zval *default_value, void **cache_slot)
+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_class_entry *ce;
-
- if (EXPECTED(arg_num <= zf->common.num_args)) {
- cur_arg_info = &zf->common.arg_info[arg_num-1];
- } else if (UNEXPECTED(zf->common.fn_flags & ZEND_ACC_VARIADIC)) {
- cur_arg_info = &zf->common.arg_info[zf->common.num_args];
- } else {
- return 1;
- }
-
- ce = NULL;
- if (UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, &ce, cache_slot, default_value, zf->common.scope, 0))) {
- zend_verify_arg_error(zf, cur_arg_info, arg_num, ce, arg);
- return 0;
- }
-
- return 1;
-}
-
-static zend_always_inline int zend_verify_recv_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zval *default_value, void **cache_slot)
-{
- zend_arg_info *cur_arg_info = &zf->common.arg_info[arg_num-1];
- zend_class_entry *ce;
ZEND_ASSERT(arg_num <= zf->common.num_args);
cur_arg_info = &zf->common.arg_info[arg_num-1];
- ce = NULL;
- if (UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, &ce, cache_slot, default_value, zf->common.scope, 0))) {
- zend_verify_arg_error(zf, cur_arg_info, arg_num, ce, arg);
+ 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, zval *default_value, void **cache_slot)
+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_class_entry *ce;
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];
- ce = NULL;
- if (UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, &ce, cache_slot, default_value, zf->common.scope, 0))) {
- zend_verify_arg_error(zf, cur_arg_info, arg_num, ce, arg);
+ 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 int zend_verify_internal_arg_types(zend_function *fbc, zend_execute_data *call)
+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 *p = ZEND_CALL_ARG(call, 1);
- void *dummy_cache_slot;
+ zval *arg = ZEND_CALL_ARG(call, 1);
for (i = 0; i < num_args; ++i) {
- dummy_cache_slot = NULL;
- if (UNEXPECTED(!zend_verify_arg_type(fbc, i + 1, p, NULL, &dummy_cache_slot))) {
- EG(current_execute_data) = call->prev_execute_data;
+ 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;
}
- p++;
+ 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);
@@ -1171,14 +1131,14 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(zend_execute_data *
}
static ZEND_COLD void zend_verify_return_error(
- const zend_function *zf, const zend_class_entry *ce, zval *value)
+ 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;
const char *need_msg, *need_kind, *need_or_null, *given_msg, *given_kind;
zend_verify_type_error_common(
- zf, arg_info, ce, value,
+ zf, arg_info, cache_slot, value,
&fname, &fsep, &fclass, &need_msg, &need_kind, &need_or_null, &given_msg, &given_kind);
zend_type_error("Return value of %s%s%s() must %s%s%s, %s%s returned",
@@ -1187,14 +1147,14 @@ static ZEND_COLD void zend_verify_return_error(
#if ZEND_DEBUG
static ZEND_COLD void zend_verify_internal_return_error(
- const zend_function *zf, const zend_class_entry *ce, zval *value)
+ 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;
const char *need_msg, *need_kind, *need_or_null, *given_msg, *given_kind;
zend_verify_type_error_common(
- zf, arg_info, ce, value,
+ zf, arg_info, cache_slot, value,
&fname, &fsep, &fclass, &need_msg, &need_kind, &need_or_null, &given_msg, &given_kind);
zend_error_noreturn(E_CORE_ERROR, "Return value of %s%s%s() must %s%s%s, %s%s returned",
@@ -1222,10 +1182,9 @@ static ZEND_COLD void zend_verify_void_return_error(const zend_function *zf, con
static int zend_verify_internal_return_type(zend_function *zf, zval *ret)
{
zend_internal_arg_info *ret_info = zf->internal_function.arg_info - 1;
- zend_class_entry *ce = NULL;
void *dummy_cache_slot = NULL;
- if (ZEND_TYPE_CODE(ret_info->type) == IS_VOID) {
+ if (ZEND_TYPE_IS_MASK(ret_info->type) && (ZEND_TYPE_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;
@@ -1233,8 +1192,8 @@ static int zend_verify_internal_return_type(zend_function *zf, zval *ret)
return 1;
}
- if (UNEXPECTED(!zend_check_type(ret_info->type, ret, &ce, &dummy_cache_slot, NULL, NULL, 1))) {
- zend_verify_internal_return_error(zf, ce, ret);
+ 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;
}
@@ -1245,33 +1204,28 @@ static int zend_verify_internal_return_type(zend_function *zf, zval *ret)
static zend_always_inline void zend_verify_return_type(zend_function *zf, zval *ret, void **cache_slot)
{
zend_arg_info *ret_info = zf->common.arg_info - 1;
- zend_class_entry *ce = NULL;
- if (UNEXPECTED(!zend_check_type(ret_info->type, ret, &ce, cache_slot, NULL, NULL, 1))) {
- zend_verify_return_error(zf, ce, ret);
+ if (UNEXPECTED(!zend_check_type(ret_info->type, ret, cache_slot, NULL, 1, 0))) {
+ zend_verify_return_error(zf, cache_slot, ret);
}
}
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_arg_info *ret_info = zf->common.arg_info - 1;
- if (ZEND_TYPE_IS_SET(ret_info->type) && UNEXPECTED(ZEND_TYPE_CODE(ret_info->type) != IS_VOID)) {
- zend_class_entry *ce = NULL;
- if (ZEND_TYPE_IS_CLASS(ret_info->type)) {
- if (EXPECTED(*cache_slot)) {
- ce = (zend_class_entry*) *cache_slot;
- } else {
- ce = zend_fetch_class(ZEND_TYPE_NAME(ret_info->type), (ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD));
- if (ce) {
- *cache_slot = (void*)ce;
- }
+ // TODO: Eliminate this!
+ if (ZEND_TYPE_IS_CLASS(ret_info->type)) {
+ if (UNEXPECTED(!*cache_slot)) {
+ zend_class_entry *ce = zend_fetch_class(ZEND_TYPE_NAME(ret_info->type), (ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD));
+ if (ce) {
+ *cache_slot = (void *) ce;
}
}
- zend_verify_return_error(zf, ce, NULL);
- return 0;
}
- return 1;
+ 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)
@@ -1281,12 +1235,12 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(void)
{
- zend_error(E_WARNING, "Illegal offset type");
+ 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(object, dim, value);
+ 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);
@@ -1317,25 +1271,15 @@ static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPL
static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *property OPLINE_DC EXECUTE_DATA_DC)
{
- zend_free_op free_op_data1;
zval *value;
zval *z;
zval rv, res;
- value = get_op_data_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1, &free_op_data1);
- if ((z = Z_OBJ_HT_P(object)->read_dimension(object, property, BP_VAR_R, &rv)) != NULL) {
-
- if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get) {
- zval rv2;
- zval *value = Z_OBJ_HT_P(z)->get(z, &rv2);
+ 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 (z == &rv) {
- zval_ptr_dtor(&rv);
- }
- ZVAL_COPY_VALUE(z, value);
- }
if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) {
- Z_OBJ_HT_P(object)->write_dimension(object, property, &res);
+ Z_OBJ_HT_P(object)->write_dimension(Z_OBJ_P(object), property, &res);
}
if (z == &rv) {
zval_ptr_dtor(&rv);
@@ -1350,7 +1294,7 @@ static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *
ZVAL_NULL(EX_VAR(opline->result.var));
}
}
- FREE_OP(free_op_data1);
+ 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)
@@ -1400,7 +1344,7 @@ try_again:
case IS_NULL:
case IS_FALSE:
case IS_TRUE:
- zend_error(E_NOTICE, "String offset cast occurred");
+ zend_error(E_WARNING, "String offset cast occurred");
break;
case IS_REFERENCE:
dim = Z_REFVAL_P(dim);
@@ -1530,7 +1474,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(z
{
zend_string *tmp_property_name;
zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
- zend_error(E_NOTICE, "Trying to get property '%s' of non-object", ZSTR_VAL(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);
}
@@ -1542,12 +1486,6 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(c
ZSTR_VAL(fbc->common.function_name));
}
-static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_abstract_method(const zend_function *fbc)
-{
- zend_throw_error(NULL, "Cannot call abstract method %s::%s()",
- ZSTR_VAL(fbc->common.scope->name), 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;
@@ -1622,7 +1560,7 @@ static zend_property_info *zend_get_prop_not_accepting_double(zend_reference *re
{
zend_property_info *prop;
ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
- if (ZEND_TYPE_CODE(prop->type) != IS_DOUBLE) {
+ if (!ZEND_TYPE_IS_MASK(prop->type) || !(ZEND_TYPE_MASK(prop->type) & MAY_BE_DOUBLE)) {
return prop;
}
} ZEND_REF_FOREACH_TYPE_SOURCES_END();
@@ -1653,19 +1591,20 @@ static ZEND_COLD zend_long zend_throw_incdec_ref_error(zend_reference *ref OPLIN
}
static ZEND_COLD zend_long zend_throw_incdec_prop_error(zend_property_info *prop OPLINE_DC) {
- const char *prop_type1, *prop_type2;
- zend_format_type(prop->type, &prop_type1, &prop_type2);
+ zend_string *type_str = zend_type_to_string(prop->type);
if (ZEND_IS_INCREMENT(opline->opcode)) {
- zend_type_error("Cannot increment property %s::$%s of type %s%s past its maximal value",
+ zend_type_error("Cannot increment property %s::$%s of type %s past its maximal value",
ZSTR_VAL(prop->ce->name),
zend_get_unmangled_property_name(prop->name),
- prop_type1, prop_type2);
+ ZSTR_VAL(type_str));
+ zend_string_release(type_str);
return ZEND_LONG_MAX;
} else {
- zend_type_error("Cannot decrement property %s::$%s of type %s%s past its minimal value",
+ zend_type_error("Cannot decrement property %s::$%s of type %s past its minimal value",
ZSTR_VAL(prop->ce->name),
zend_get_unmangled_property_name(prop->name),
- prop_type1, prop_type2);
+ ZSTR_VAL(type_str));
+ zend_string_release(type_str);
return ZEND_LONG_MIN;
}
}
@@ -1800,30 +1739,20 @@ static void zend_post_incdec_property_zval(zval *prop, zend_property_info *prop_
}
}
-static zend_never_inline void zend_post_incdec_overloaded_property(zval *object, zval *property, void **cache_slot OPLINE_DC EXECUTE_DATA_DC)
+static zend_never_inline void zend_post_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC)
{
- zval rv, obj;
+ zval rv;
zval *z;
zval z_copy;
- ZVAL_OBJ(&obj, Z_OBJ_P(object));
- Z_ADDREF(obj);
- z = Z_OBJ_HT(obj)->read_property(&obj, property, BP_VAR_R, cache_slot, &rv);
+ GC_ADDREF(object);
+ z =object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(Z_OBJ(obj));
+ OBJ_RELEASE(object);
ZVAL_UNDEF(EX_VAR(opline->result.var));
return;
}
- if (UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && Z_OBJ_HT_P(z)->get) {
- zval rv2;
- zval *value = Z_OBJ_HT_P(z)->get(z, &rv2);
- if (z == &rv) {
- zval_ptr_dtor(&rv);
- }
- ZVAL_COPY_VALUE(z, value);
- }
-
ZVAL_COPY_DEREF(&z_copy, z);
ZVAL_COPY(EX_VAR(opline->result.var), &z_copy);
if (ZEND_IS_INCREMENT(opline->opcode)) {
@@ -1831,38 +1760,28 @@ static zend_never_inline void zend_post_incdec_overloaded_property(zval *object,
} else {
decrement_function(&z_copy);
}
- Z_OBJ_HT(obj)->write_property(&obj, property, &z_copy, cache_slot);
- OBJ_RELEASE(Z_OBJ(obj));
+ object->handlers->write_property(object, name, &z_copy, cache_slot);
+ OBJ_RELEASE(object);
zval_ptr_dtor(&z_copy);
zval_ptr_dtor(z);
}
-static zend_never_inline void zend_pre_incdec_overloaded_property(zval *object, zval *property, void **cache_slot OPLINE_DC EXECUTE_DATA_DC)
+static zend_never_inline void zend_pre_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC)
{
zval rv;
- zval *z, obj;
+ zval *z;
zval z_copy;
- ZVAL_OBJ(&obj, Z_OBJ_P(object));
- Z_ADDREF(obj);
- z = Z_OBJ_HT(obj)->read_property(&obj, property, BP_VAR_R, cache_slot, &rv);
+ GC_ADDREF(object);
+ z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(Z_OBJ(obj));
+ OBJ_RELEASE(object);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
return;
}
- if (UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && Z_OBJ_HT_P(z)->get) {
- zval rv2;
- zval *value = Z_OBJ_HT_P(z)->get(z, &rv2);
-
- if (z == &rv) {
- zval_ptr_dtor(&rv);
- }
- ZVAL_COPY_VALUE(z, value);
- }
ZVAL_COPY_DEREF(&z_copy, z);
if (ZEND_IS_INCREMENT(opline->opcode)) {
increment_function(&z_copy);
@@ -1872,45 +1791,35 @@ static zend_never_inline void zend_pre_incdec_overloaded_property(zval *object,
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &z_copy);
}
- Z_OBJ_HT(obj)->write_property(&obj, property, &z_copy, cache_slot);
- OBJ_RELEASE(Z_OBJ(obj));
+ object->handlers->write_property(object, name, &z_copy, cache_slot);
+ OBJ_RELEASE(object);
zval_ptr_dtor(&z_copy);
zval_ptr_dtor(z);
}
-static zend_never_inline void zend_assign_op_overloaded_property(zval *object, zval *property, void **cache_slot, zval *value OPLINE_DC EXECUTE_DATA_DC)
+static zend_never_inline void zend_assign_op_overloaded_property(zend_object *object, zend_string *name, void **cache_slot, zval *value OPLINE_DC EXECUTE_DATA_DC)
{
zval *z;
- zval rv, obj, res;
+ zval rv, res;
- ZVAL_OBJ(&obj, Z_OBJ_P(object));
- Z_ADDREF(obj);
- z = Z_OBJ_HT(obj)->read_property(&obj, property, BP_VAR_R, cache_slot, &rv);
+ GC_ADDREF(object);
+ z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
if (UNEXPECTED(EG(exception))) {
- OBJ_RELEASE(Z_OBJ(obj));
+ OBJ_RELEASE(object);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_UNDEF(EX_VAR(opline->result.var));
}
return;
}
- if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get) {
- zval rv2;
- zval *value = Z_OBJ_HT_P(z)->get(z, &rv2);
-
- if (z == &rv) {
- zval_ptr_dtor(&rv);
- }
- ZVAL_COPY_VALUE(z, value);
- }
if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) {
- Z_OBJ_HT(obj)->write_property(&obj, property, &res, cache_slot);
+ object->handlers->write_property(object, name, &res, cache_slot);
}
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &res);
}
zval_ptr_dtor(z);
zval_ptr_dtor(&res);
- OBJ_RELEASE(Z_OBJ(obj));
+ OBJ_RELEASE(object);
}
/* Utility Functions for Extensions */
@@ -1976,16 +1885,10 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_invalid_method_call(z
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_non_static_method_call(const zend_function *fbc)
{
- if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
- zend_error(E_DEPRECATED,
- "Non-static method %s::%s() should not be called statically",
- ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
- } else {
- zend_throw_error(
- zend_ce_error,
- "Non-static method %s::%s() cannot be called statically",
- ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
- }
+ zend_throw_error(
+ zend_ce_error,
+ "Non-static method %s::%s() cannot be called statically",
+ ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
}
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num)
@@ -1999,17 +1902,17 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(con
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_scalar_as_array(void)
{
- zend_error(E_WARNING, "Cannot use a scalar value as an array");
+ zend_throw_error(NULL, "Cannot use a scalar value as an array");
}
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void)
{
- zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
}
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
{
- zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
+ zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
}
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_new_element_for_string(void)
@@ -2019,8 +1922,6 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_new_element_for_s
static ZEND_COLD void zend_binary_assign_op_dim_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC)
{
- zend_free_op free_op_data1;
-
if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
if (opline->op2_type == IS_UNUSED) {
zend_use_new_element_for_string();
@@ -2028,11 +1929,10 @@ static ZEND_COLD void zend_binary_assign_op_dim_slow(zval *container, zval *dim
zend_check_string_offset(dim, BP_VAR_RW EXECUTE_DATA_CC);
zend_wrong_string_offset(EXECUTE_DATA_C);
}
- } else if (EXPECTED(!Z_ISERROR_P(container))) {
+ } else {
zend_use_scalar_as_array();
}
- get_op_data_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1, &free_op_data1);
- FREE_OP(free_op_data1);
+ FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
}
static zend_never_inline zend_uchar slow_index_convert(const zval *dim, zend_value *value EXECUTE_DATA_DC)
@@ -2194,13 +2094,13 @@ fetch_from_array:
retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval));
if (UNEXPECTED(retval == NULL)) {
zend_cannot_add_element();
- ZVAL_ERROR(result);
+ ZVAL_UNDEF(result);
return;
}
} else {
retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC);
if (UNEXPECTED(!retval)) {
- ZVAL_ERROR(result);
+ ZVAL_UNDEF(result);
return;
}
}
@@ -2215,7 +2115,7 @@ fetch_from_array:
if (type != BP_VAR_UNSET) {
if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
if (UNEXPECTED(!zend_verify_ref_array_assignable(ref))) {
- ZVAL_ERROR(result);
+ ZVAL_UNDEF(result);
return;
}
}
@@ -2233,7 +2133,7 @@ fetch_from_array:
zend_check_string_offset(dim, type EXECUTE_DATA_CC);
zend_wrong_string_offset(EXECUTE_DATA_C);
}
- ZVAL_ERROR(result);
+ ZVAL_UNDEF(result);
} else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
dim = ZVAL_UNDEFINED_OP2();
@@ -2241,7 +2141,7 @@ fetch_from_array:
if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
dim++;
}
- retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);
+ retval = Z_OBJ_HT_P(container)->read_dimension(Z_OBJ_P(container), dim, type, result);
if (UNEXPECTED(retval == &EG(uninitialized_zval))) {
zend_class_entry *ce = Z_OBJCE_P(container);
@@ -2265,7 +2165,8 @@ fetch_from_array:
ZVAL_INDIRECT(result, retval);
}
} else {
- ZVAL_ERROR(result);
+ ZEND_ASSERT(EG(exception) && "read_dimension() returned NULL without exception");
+ ZVAL_UNDEF(result);
}
} else {
if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
@@ -2283,15 +2184,13 @@ return_null:
}
ZVAL_NULL(result);
}
- } else if (EXPECTED(Z_ISERROR_P(container))) {
- ZVAL_ERROR(result);
} else {
if (type == BP_VAR_UNSET) {
- zend_error(E_WARNING, "Cannot unset offset in a non-array variable");
- ZVAL_NULL(result);
+ zend_throw_error(NULL, "Cannot unset offset in a non-array variable");
+ ZVAL_UNDEF(result);
} else {
zend_use_scalar_as_array();
- ZVAL_ERROR(result);
+ ZVAL_UNDEF(result);
}
}
}
@@ -2356,7 +2255,7 @@ try_string_offset:
case IS_FALSE:
case IS_TRUE:
if (type != BP_VAR_IS) {
- zend_error(E_NOTICE, "String offset cast occurred");
+ zend_error(E_WARNING, "String offset cast occurred");
}
break;
case IS_REFERENCE:
@@ -2374,7 +2273,7 @@ try_string_offset:
if (UNEXPECTED(Z_STRLEN_P(container) < (size_t)((offset < 0) ? -offset : (offset + 1)))) {
if (type != BP_VAR_IS) {
- zend_error(E_NOTICE, "Uninitialized string offset: " ZEND_LONG_FMT, offset);
+ zend_error(E_WARNING, "Uninitialized string offset: " ZEND_LONG_FMT, offset);
ZVAL_EMPTY_STRING(result);
} else {
ZVAL_NULL(result);
@@ -2396,7 +2295,7 @@ try_string_offset:
if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
dim++;
}
- retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);
+ retval = Z_OBJ_HT_P(container)->read_dimension(Z_OBJ_P(container), dim, type, result);
ZEND_ASSERT(result != NULL);
if (retval) {
@@ -2416,7 +2315,7 @@ try_string_offset:
ZVAL_UNDEFINED_OP2();
}
if (!is_list && type != BP_VAR_IS) {
- zend_error(E_NOTICE, "Trying to access array offset on value of type %s",
+ zend_error(E_WARNING, "Trying to access array offset on value of type %s",
zend_zval_type_name(container));
}
ZVAL_NULL(result);
@@ -2476,7 +2375,7 @@ str_idx:
ZVAL_UNDEFINED_OP2();
goto str_idx;
} else {
- zend_error(E_WARNING, "Illegal offset type in isset or empty");
+ zend_type_error("Illegal offset type in isset or empty");
return NULL;
}
}
@@ -2488,7 +2387,7 @@ static zend_never_inline int ZEND_FASTCALL zend_isset_dim_slow(zval *container,
}
if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
- return Z_OBJ_HT_P(container)->has_dimension(container, offset, 0);
+ return Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 0);
} else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
zend_long lval;
@@ -2527,7 +2426,7 @@ static zend_never_inline int ZEND_FASTCALL zend_isempty_dim_slow(zval *container
}
if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
- return !Z_OBJ_HT_P(container)->has_dimension(container, offset, 1);
+ return !Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 1);
} else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
zend_long lval;
@@ -2609,7 +2508,7 @@ static zend_never_inline uint32_t ZEND_FASTCALL zend_array_key_exists_slow(zval
if (UNEXPECTED(Z_TYPE_INFO_P(subject) == IS_UNDEF)) {
ZVAL_UNDEFINED_OP2();
}
- zend_internal_type_error(EX_USES_STRICT_TYPES(), "array_key_exists() expects parameter 2 to be array, %s given", zend_get_type_by_const(Z_TYPE_P(subject)));
+ zend_type_error("array_key_exists() expects parameter 2 to be array, %s given", zend_get_type_by_const(Z_TYPE_P(subject)));
return IS_NULL;
}
}
@@ -2619,38 +2518,15 @@ static zend_always_inline zend_bool promotes_to_array(zval *val) {
|| (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE);
}
-static zend_always_inline zend_bool promotes_to_object(zval *val) {
- ZVAL_DEREF(val);
- return Z_TYPE_P(val) <= IS_FALSE
- || (Z_TYPE_P(val) == IS_STRING && Z_STRLEN_P(val) == 0);
-}
-
static zend_always_inline zend_bool check_type_array_assignable(zend_type type) {
- if (!type) {
- return 1;
- }
- return ZEND_TYPE_IS_CODE(type)
- && (ZEND_TYPE_CODE(type) == IS_ARRAY || ZEND_TYPE_CODE(type) == IS_ITERABLE);
-}
-
-static zend_always_inline zend_bool check_type_stdClass_assignable(zend_type type) {
- if (!type) {
+ if (!ZEND_TYPE_IS_SET(type)) {
return 1;
}
- if (ZEND_TYPE_IS_CLASS(type)) {
- if (ZEND_TYPE_IS_CE(type)) {
- return ZEND_TYPE_CE(type) == zend_standard_class_def;
- } else {
- return zend_string_equals_literal_ci(ZEND_TYPE_NAME(type), "stdclass");
- }
- } else {
- return ZEND_TYPE_CODE(type) == IS_OBJECT;
- }
+ return ZEND_TYPE_IS_MASK(type) && (ZEND_TYPE_MASK(type) & (MAY_BE_ITERABLE|MAY_BE_ARRAY));
}
-/* Checks whether an array can be assigned to the reference. Returns conflicting property if
- * assignment is not possible, NULL otherwise. */
-static zend_never_inline zend_bool zend_verify_ref_array_assignable(zend_reference *ref) {
+/* Checks whether an array can be assigned to the reference. Throws error if not assignable. */
+ZEND_API zend_bool zend_verify_ref_array_assignable(zend_reference *ref) {
zend_property_info *prop;
ZEND_ASSERT(ZEND_REF_HAS_TYPE_SOURCES(ref));
ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
@@ -2662,20 +2538,6 @@ static zend_never_inline zend_bool zend_verify_ref_array_assignable(zend_referen
return 1;
}
-/* Checks whether an stdClass can be assigned to the reference. Returns conflicting property if
- * assignment is not possible, NULL otherwise. */
-static zend_never_inline zend_bool zend_verify_ref_stdClass_assignable(zend_reference *ref) {
- zend_property_info *prop;
- ZEND_ASSERT(ZEND_REF_HAS_TYPE_SOURCES(ref));
- ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
- if (!check_type_stdClass_assignable(prop->type)) {
- zend_throw_auto_init_in_ref_error(prop, "stdClass");
- return 0;
- }
- } ZEND_REF_FOREACH_TYPE_SOURCES_END();
- return 1;
-}
-
static zend_property_info *zend_object_fetch_property_type_info(
zend_object *obj, zval *slot)
{
@@ -2711,21 +2573,6 @@ static zend_never_inline zend_bool zend_handle_fetch_obj_flags(
}
}
break;
- case ZEND_FETCH_OBJ_WRITE:
- if (promotes_to_object(ptr)) {
- if (!prop_info) {
- prop_info = zend_object_fetch_property_type_info(obj, ptr);
- if (!prop_info) {
- break;
- }
- }
- if (!check_type_stdClass_assignable(prop_info->type)) {
- zend_throw_auto_init_in_prop_error(prop_info, "stdClass");
- if (result) ZVAL_ERROR(result);
- return 0;
- }
- }
- break;
case ZEND_FETCH_REF:
if (Z_TYPE_P(ptr) != IS_REFERENCE) {
if (!prop_info) {
@@ -2755,8 +2602,10 @@ static zend_never_inline zend_bool zend_handle_fetch_obj_flags(
static zend_always_inline void zend_fetch_property_address(zval *result, zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, void **cache_slot, int type, uint32_t flags, zend_bool init_undef OPLINE_DC EXECUTE_DATA_DC)
{
zval *ptr;
+ zend_object *zobj;
+ zend_string *name, *tmp_name;
- if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
+ if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
do {
if (Z_ISREF_P(container) && Z_TYPE_P(Z_REFVAL_P(container)) == IS_OBJECT) {
container = Z_REFVAL_P(container);
@@ -2775,17 +2624,16 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
return;
}
- container = make_real_object(container, prop_ptr OPLINE_CC EXECUTE_DATA_CC);
- if (UNEXPECTED(!container)) {
- ZVAL_ERROR(result);
- return;
- }
+ zend_throw_non_object_error(container, prop_ptr OPLINE_CC EXECUTE_DATA_CC);
+ ZVAL_ERROR(result);
+ return;
} while (0);
}
+
+ zobj = Z_OBJ_P(container);
if (prop_op_type == IS_CONST &&
- EXPECTED(Z_OBJCE_P(container) == CACHED_PTR_EX(cache_slot))) {
+ EXPECTED(zobj->ce == CACHED_PTR_EX(cache_slot))) {
uintptr_t prop_offset = (uintptr_t)CACHED_PTR_EX(cache_slot + 1);
- zend_object *zobj = Z_OBJ_P(container);
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) {
ptr = OBJ_PROP(zobj, prop_offset);
@@ -2813,9 +2661,15 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
}
}
}
- ptr = Z_OBJ_HT_P(container)->get_property_ptr_ptr(container, prop_ptr, type, cache_slot);
+
+ if (prop_op_type == IS_CONST) {
+ name = Z_STR_P(prop_ptr);
+ } else {
+ name = zval_get_tmp_string(prop_ptr, &tmp_name);
+ }
+ ptr = zobj->handlers->get_property_ptr_ptr(zobj, name, type, cache_slot);
if (NULL == ptr) {
- ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type, cache_slot, result);
+ ptr = zobj->handlers->read_property(zobj, name, type, cache_slot, result);
if (ptr == result) {
if (UNEXPECTED(Z_ISREF_P(ptr) && Z_REFCOUNT_P(ptr) == 1)) {
ZVAL_UNREF(ptr);
@@ -2867,8 +2721,6 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
zval_ptr_dtor(&variable);
variable_ptr = &EG(uninitialized_zval);
- } else if (/*OP_DATA_TYPE == IS_VAR &&*/ UNEXPECTED(Z_ISERROR_P(value_ptr))) {
- variable_ptr = &EG(uninitialized_zval);
} else if (/*OP_DATA_TYPE == IS_VAR &&*/
(opline->extended_value & ZEND_RETURNS_FUNCTION) &&
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
@@ -2924,7 +2776,6 @@ static zend_never_inline void zend_assign_to_property_reference_var_var(zval *co
}
static zend_never_inline int zend_fetch_static_property_address_ex(zval **retval, zend_property_info **prop_info, uint32_t cache_slot, int fetch_type OPLINE_DC EXECUTE_DATA_DC) {
- zend_free_op free_op1;
zend_string *name, *tmp_name;
zend_class_entry *ce;
zend_property_info *property_info;
@@ -2966,7 +2817,7 @@ static zend_never_inline int zend_fetch_static_property_address_ex(zval **retval
if (EXPECTED(op1_type == IS_CONST)) {
name = Z_STR_P(RT_CONSTANT(opline, opline->op1));
} else {
- zval *varname = get_zval_ptr_undef(opline->op1_type, opline->op1, &free_op1, BP_VAR_R);
+ zval *varname = get_zval_ptr_undef(opline->op1_type, opline->op1, BP_VAR_R);
if (EXPECTED(Z_TYPE_P(varname) == IS_STRING)) {
name = Z_STR_P(varname);
tmp_name = NULL;
@@ -2983,9 +2834,7 @@ static zend_never_inline int zend_fetch_static_property_address_ex(zval **retval
if (UNEXPECTED(op1_type != IS_CONST)) {
zend_tmp_string_release(tmp_name);
- if (op1_type != IS_CV) {
- zval_ptr_dtor_nogc(free_op1);
- }
+ FREE_OP(op1_type, opline->op1.var);
}
if (UNEXPECTED(*retval == NULL)) {
@@ -3012,7 +2861,8 @@ static zend_always_inline int zend_fetch_static_property_address(zval **retval,
property_info = CACHED_PTR(cache_slot + sizeof(void *) * 2);
if ((fetch_type == BP_VAR_R || fetch_type == BP_VAR_RW)
- && UNEXPECTED(Z_TYPE_P(*retval) == IS_UNDEF) && UNEXPECTED(property_info->type != 0)) {
+ && UNEXPECTED(Z_TYPE_P(*retval) == IS_UNDEF)
+ && UNEXPECTED(ZEND_TYPE_IS_SET(property_info->type))) {
zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization",
ZSTR_VAL(property_info->ce->name),
zend_get_unmangled_property_name(property_info->name));
@@ -3025,7 +2875,7 @@ static zend_always_inline int zend_fetch_static_property_address(zval **retval,
}
}
- if (flags && property_info->type) {
+ if (flags && ZEND_TYPE_IS_SET(property_info->type)) {
zend_handle_fetch_obj_flags(NULL, *retval, NULL, property_info, flags);
}
@@ -3037,58 +2887,59 @@ static zend_always_inline int zend_fetch_static_property_address(zval **retval,
}
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(zend_property_info *prop1, zend_property_info *prop2, zval *zv) {
- const char *prop1_type1, *prop1_type2, *prop2_type1, *prop2_type2;
- zend_format_type(prop1->type, &prop1_type1, &prop1_type2);
- zend_format_type(prop2->type, &prop2_type1, &prop2_type2);
- zend_type_error("Reference with value of type %s held by property %s::$%s of type %s%s is not compatible with property %s::$%s of type %s%s",
+ zend_string *type1_str = zend_type_to_string(prop1->type);
+ zend_string *type2_str = zend_type_to_string(prop2->type);
+ zend_type_error("Reference with value of type %s held by property %s::$%s of type %s is not compatible with property %s::$%s of type %s",
Z_TYPE_P(zv) == IS_OBJECT ? ZSTR_VAL(Z_OBJCE_P(zv)->name) : zend_get_type_by_const(Z_TYPE_P(zv)),
ZSTR_VAL(prop1->ce->name),
zend_get_unmangled_property_name(prop1->name),
- prop1_type1, prop1_type2,
+ ZSTR_VAL(type1_str),
ZSTR_VAL(prop2->ce->name),
zend_get_unmangled_property_name(prop2->name),
- prop2_type1, prop2_type2
+ ZSTR_VAL(type2_str)
);
+ zend_string_release(type1_str);
+ zend_string_release(type2_str);
}
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(zend_property_info *prop, zval *zv) {
- const char *prop_type1, *prop_type2;
- zend_format_type(prop->type, &prop_type1, &prop_type2);
- zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s%s",
+ zend_string *type_str = zend_type_to_string(prop->type);
+ zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s",
Z_TYPE_P(zv) == IS_OBJECT ? ZSTR_VAL(Z_OBJCE_P(zv)->name) : zend_get_type_by_const(Z_TYPE_P(zv)),
ZSTR_VAL(prop->ce->name),
zend_get_unmangled_property_name(prop->name),
- prop_type1, prop_type2
+ ZSTR_VAL(type_str)
);
+ zend_string_release(type_str);
}
ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(zend_property_info *prop1, zend_property_info *prop2, zval *zv) {
- const char *prop1_type1, *prop1_type2, *prop2_type1, *prop2_type2;
- zend_format_type(prop1->type, &prop1_type1, &prop1_type2);
- zend_format_type(prop2->type, &prop2_type1, &prop2_type2);
- zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s%s and property %s::$%s of type %s%s, as this would result in an inconsistent type conversion",
+ zend_string *type1_str = zend_type_to_string(prop1->type);
+ zend_string *type2_str = zend_type_to_string(prop2->type);
+ zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s and property %s::$%s of type %s, as this would result in an inconsistent type conversion",
Z_TYPE_P(zv) == IS_OBJECT ? ZSTR_VAL(Z_OBJCE_P(zv)->name) : zend_get_type_by_const(Z_TYPE_P(zv)),
ZSTR_VAL(prop1->ce->name),
zend_get_unmangled_property_name(prop1->name),
- prop1_type1, prop1_type2,
+ ZSTR_VAL(type1_str),
ZSTR_VAL(prop2->ce->name),
zend_get_unmangled_property_name(prop2->name),
- prop2_type1, prop2_type2
+ ZSTR_VAL(type2_str)
);
+ zend_string_release(type1_str);
+ zend_string_release(type2_str);
}
/* 1: valid, 0: invalid, -1: may be valid after type coercion */
static zend_always_inline int i_zend_verify_type_assignable_zval(
zend_type *type_ptr, zend_class_entry *self_ce, zval *zv, zend_bool strict) {
zend_type type = *type_ptr;
- zend_uchar type_code;
+ uint32_t type_mask;
zend_uchar zv_type = Z_TYPE_P(zv);
- if (ZEND_TYPE_ALLOW_NULL(type) && zv_type == IS_NULL) {
- return 1;
- }
-
if (ZEND_TYPE_IS_CLASS(type)) {
+ if (ZEND_TYPE_ALLOW_NULL(type) && zv_type == IS_NULL) {
+ return 1;
+ }
if (!ZEND_TYPE_IS_CE(type)) {
if (!zend_resolve_class_type(type_ptr, self_ce)) {
return 0;
@@ -3098,26 +2949,25 @@ static zend_always_inline int i_zend_verify_type_assignable_zval(
return zv_type == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), ZEND_TYPE_CE(type));
}
- type_code = ZEND_TYPE_CODE(type);
- if (type_code == zv_type ||
- (type_code == _IS_BOOL && (zv_type == IS_FALSE || zv_type == IS_TRUE))) {
+ if (ZEND_TYPE_CONTAINS_CODE(type, zv_type)) {
return 1;
}
- if (type_code == IS_ITERABLE) {
+ type_mask = ZEND_TYPE_MASK(type);
+ if (type_mask & MAY_BE_ITERABLE) {
return zend_is_iterable(zv);
}
/* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */
if (strict) {
- if (type_code == IS_DOUBLE && zv_type == IS_LONG) {
+ if ((type_mask & MAY_BE_DOUBLE) && zv_type == IS_LONG) {
return -1;
}
return 0;
}
/* No weak conversions for arrays and objects */
- if (type_code == IS_ARRAY || type_code == IS_OBJECT) {
+ if (type_mask & (MAY_BE_ARRAY|MAY_BE_OBJECT)) {
return 0;
}
@@ -3139,7 +2989,7 @@ ZEND_API zend_bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference
* must be the same (modulo nullability). To handle this, remember the first type we see and
* compare against it when coercion becomes necessary. */
zend_property_info *seen_prop = NULL;
- zend_uchar seen_type;
+ uint32_t seen_type_mask;
zend_bool needs_coercion = 0;
ZEND_ASSERT(Z_TYPE_P(zv) != IS_REFERENCE);
@@ -3156,14 +3006,16 @@ ZEND_API zend_bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference
if (!seen_prop) {
seen_prop = prop;
- seen_type = ZEND_TYPE_IS_CLASS(prop->type) ? IS_OBJECT : ZEND_TYPE_CODE(prop->type);
- } else if (needs_coercion && seen_type != ZEND_TYPE_CODE(prop->type)) {
+ seen_type_mask = ZEND_TYPE_IS_CLASS(prop->type)
+ ? MAY_BE_OBJECT : ZEND_TYPE_MASK(ZEND_TYPE_WITHOUT_NULL(prop->type));
+ } else if (needs_coercion
+ && seen_type_mask != ZEND_TYPE_MASK(ZEND_TYPE_WITHOUT_NULL(prop->type))) {
zend_throw_conflicting_coercion_error(seen_prop, prop, zv);
return 0;
}
} ZEND_REF_FOREACH_TYPE_SOURCES_END();
- if (UNEXPECTED(needs_coercion && !zend_verify_weak_scalar_type_hint(seen_type, zv))) {
+ if (UNEXPECTED(needs_coercion && !zend_verify_weak_scalar_type_hint(seen_type_mask, zv))) {
zend_throw_ref_type_error_zval(seen_prop, zv);
return 0;
}
@@ -3224,12 +3076,13 @@ ZEND_API zend_bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(zend_propert
if (result < 0) {
zend_property_info *ref_prop = ZEND_REF_FIRST_SOURCE(Z_REF_P(orig_val));
- if (ZEND_TYPE_CODE(prop_info->type) != ZEND_TYPE_CODE(ref_prop->type)) {
+ if (ZEND_TYPE_MASK(ZEND_TYPE_WITHOUT_NULL(prop_info->type))
+ != ZEND_TYPE_MASK(ZEND_TYPE_WITHOUT_NULL(ref_prop->type))) {
/* Invalid due to conflicting coercion */
zend_throw_ref_type_error_type(ref_prop, prop_info, val);
return 0;
}
- if (zend_verify_weak_scalar_type_hint(ZEND_TYPE_CODE(prop_info->type), val)) {
+ if (zend_verify_weak_scalar_type_hint(ZEND_TYPE_MASK(prop_info->type), val)) {
return 1;
}
}
@@ -3314,7 +3167,7 @@ static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DAT
Z_ADDREF_P(result);
} else {
ZVAL_NULL(result);
- zend_error(E_NOTICE,"Undefined variable: this");
+ zend_error(E_WARNING, "Undefined variable: this");
}
break;
case BP_VAR_IS:
@@ -3919,7 +3772,8 @@ static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num,
}
} else if (kind == ZEND_LIVE_SILENCE) {
/* restore previous error_reporting value */
- if (!EG(error_reporting) && Z_LVAL_P(var) != 0) {
+ if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
+ && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) {
EG(error_reporting) = Z_LVAL_P(var);
}
}
@@ -3995,9 +3849,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) {
zend_non_static_method_call(fbc);
- if (UNEXPECTED(EG(exception) != NULL)) {
- return NULL;
- }
+ return NULL;
}
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
init_func_run_time_cache(&fbc->op_array);
@@ -4028,7 +3880,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
}
/* }}} */
-static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zval *function, uint32_t num_args) /* {{{ */
+static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_object *function, uint32_t num_args) /* {{{ */
{
zend_function *fbc;
void *object_or_called_scope;
@@ -4036,8 +3888,8 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zval *
zend_object *object;
uint32_t call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
- if (EXPECTED(Z_OBJ_HANDLER_P(function, get_closure)) &&
- EXPECTED(Z_OBJ_HANDLER_P(function, get_closure)(function, &called_scope, &fbc, &object) == SUCCESS)) {
+ if (EXPECTED(function->handlers->get_closure) &&
+ EXPECTED(function->handlers->get_closure(function, &called_scope, &fbc, &object, 0) == SUCCESS)) {
object_or_called_scope = called_scope;
if (fbc->common.fn_flags & ZEND_ACC_CLOSURE) {
@@ -4119,9 +3971,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
}
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
zend_non_static_method_call(fbc);
- if (UNEXPECTED(EG(exception) != NULL)) {
- return NULL;
- }
+ return NULL;
}
object_or_called_scope = called_scope;
} else {
@@ -4251,43 +4101,6 @@ already_compiled:
}
/* }}} */
-static ZEND_COLD int ZEND_FASTCALL zend_do_fcall_overloaded(zend_execute_data *call, zval *ret) /* {{{ */
-{
- zend_function *fbc = call->func;
- zend_object *object;
-
- /* Not sure what should be done here if it's a static method */
- if (UNEXPECTED(Z_TYPE(call->This) != IS_OBJECT)) {
- zend_vm_stack_free_args(call);
- if (fbc->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
- zend_string_release_ex(fbc->common.function_name, 0);
- }
- efree(fbc);
- zend_vm_stack_free_call_frame(call);
-
- zend_throw_error(NULL, "Cannot call overloaded function for non-object");
- return 0;
- }
-
- object = Z_OBJ(call->This);
-
- ZVAL_NULL(ret);
-
- EG(current_execute_data) = call;
- object->handlers->call_method(fbc->common.function_name, object, call, ret);
- EG(current_execute_data) = call->prev_execute_data;
-
- zend_vm_stack_free_args(call);
-
- if (fbc->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
- zend_string_release_ex(fbc->common.function_name, 0);
- }
- efree(fbc);
-
- return 1;
-}
-/* }}} */
-
static zend_never_inline zend_bool ZEND_FASTCALL zend_fe_reset_iterator(zval *array_ptr, int by_ref OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
{
zend_class_entry *ce = Z_OBJCE_P(array_ptr);
@@ -4335,96 +4148,30 @@ static zend_always_inline int _zend_quick_get_constant(
const zval *key, uint32_t flags, int check_defined_only OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
{
zval *zv;
- const zval *orig_key = key;
zend_constant *c = NULL;
+ /* null/true/false are resolved during compilation, so don't check for them here. */
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
if (zv) {
c = (zend_constant*)Z_PTR_P(zv);
- } else {
+ } else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
key++;
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
- if (zv && (ZEND_CONSTANT_FLAGS((zend_constant*)Z_PTR_P(zv)) & CONST_CS) == 0) {
+ if (zv) {
c = (zend_constant*)Z_PTR_P(zv);
- } else {
- if ((flags & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) {
- key++;
- zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
- if (zv) {
- c = (zend_constant*)Z_PTR_P(zv);
- } else {
- key++;
- zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
- if (zv && (ZEND_CONSTANT_FLAGS((zend_constant*)Z_PTR_P(zv)) & CONST_CS) == 0) {
- c = (zend_constant*)Z_PTR_P(zv);
- }
- }
- }
}
}
if (!c) {
if (!check_defined_only) {
- if ((opline->op1.num & IS_CONSTANT_UNQUALIFIED) != 0) {
- char *actual = (char *)zend_memrchr(Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)), '\\', Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)));
- if (!actual) {
- ZVAL_STR_COPY(EX_VAR(opline->result.var), Z_STR_P(RT_CONSTANT(opline, opline->op2)));
- } else {
- actual++;
- ZVAL_STRINGL(EX_VAR(opline->result.var),
- actual, Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)) - (actual - Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))));
- }
- /* non-qualified constant - allow text substitution */
- zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)",
- Z_STRVAL_P(EX_VAR(opline->result.var)), Z_STRVAL_P(EX_VAR(opline->result.var)));
- } else {
- zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
- ZVAL_UNDEF(EX_VAR(opline->result.var));
- }
+ zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
+ ZVAL_UNDEF(EX_VAR(opline->result.var));
}
return FAILURE;
}
if (!check_defined_only) {
ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
- if (!(ZEND_CONSTANT_FLAGS(c) & (CONST_CS|CONST_CT_SUBST))) {
- const char *ns_sep;
- size_t shortname_offset;
- size_t shortname_len;
- zend_bool is_deprecated;
-
- if (flags & IS_CONSTANT_UNQUALIFIED) {
- const zval *access_key;
-
- if (!(flags & IS_CONSTANT_IN_NAMESPACE)) {
- access_key = orig_key - 1;
- } else {
- if (key < orig_key + 2) {
- goto check_short_name;
- } else {
- access_key = orig_key + 2;
- }
- }
- is_deprecated = !zend_string_equals(c->name, Z_STR_P(access_key));
- } else {
-check_short_name:
- ns_sep = zend_memrchr(ZSTR_VAL(c->name), '\\', ZSTR_LEN(c->name));
- ZEND_ASSERT(ns_sep);
- /* Namespaces are always case-insensitive. Only compare shortname. */
- shortname_offset = ns_sep - ZSTR_VAL(c->name) + 1;
- shortname_len = ZSTR_LEN(c->name) - shortname_offset;
-
- is_deprecated = memcmp(ZSTR_VAL(c->name) + shortname_offset, Z_STRVAL_P(orig_key - 1) + shortname_offset, shortname_len) != 0;
- }
-
- if (is_deprecated) {
- zend_error(E_DEPRECATED,
- "Case-insensitive constants are deprecated. "
- "The correct casing for this constant is \"%s\"",
- ZSTR_VAL(c->name));
- return SUCCESS;
- }
- }
}
CACHE_PTR(opline->extended_value, c);
@@ -4492,68 +4239,68 @@ static zend_never_inline int ZEND_FASTCALL zend_quick_check_constant(
OPLINE++
-#ifndef VM_SMART_OPCODES
-# define VM_SMART_OPCODES 1
-#endif
-
-#if VM_SMART_OPCODES
-# define ZEND_VM_REPEATABLE_OPCODE \
+#define ZEND_VM_REPEATABLE_OPCODE \
do {
-# define ZEND_VM_REPEAT_OPCODE(_opcode) \
+#define ZEND_VM_REPEAT_OPCODE(_opcode) \
} while (UNEXPECTED((++opline)->opcode == _opcode)); \
OPLINE = opline; \
ZEND_VM_CONTINUE()
-# define ZEND_VM_SMART_BRANCH(_result, _check) do { \
+#define ZEND_VM_SMART_BRANCH(_result, _check) do { \
if ((_check) && UNEXPECTED(EG(exception))) { \
- break; \
- } \
- if (EXPECTED((opline+1)->opcode == ZEND_JMPZ)) { \
+ OPLINE = EX(opline); \
+ } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
if (_result) { \
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
} else { \
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
} \
- } else if (EXPECTED((opline+1)->opcode == ZEND_JMPNZ)) { \
+ } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
if (!(_result)) { \
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
} else { \
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
} \
} else { \
- break; \
+ ZVAL_BOOL(EX_VAR(opline->result.var), _result); \
+ ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
} \
ZEND_VM_CONTINUE(); \
} while (0)
-# define ZEND_VM_SMART_BRANCH_JMPZ(_result, _check) do { \
+#define ZEND_VM_SMART_BRANCH_JMPZ(_result, _check) do { \
if ((_check) && UNEXPECTED(EG(exception))) { \
- break; \
- } \
- if (_result) { \
+ OPLINE = EX(opline); \
+ } else if (_result) { \
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
} else { \
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
} \
ZEND_VM_CONTINUE(); \
} while (0)
-# define ZEND_VM_SMART_BRANCH_JMPNZ(_result, _check) do { \
+#define ZEND_VM_SMART_BRANCH_JMPNZ(_result, _check) do { \
if ((_check) && UNEXPECTED(EG(exception))) { \
- break; \
- } \
- if (!(_result)) { \
+ OPLINE = EX(opline); \
+ } else if (!(_result)) { \
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
} else { \
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
} \
ZEND_VM_CONTINUE(); \
} while (0)
+#define ZEND_VM_SMART_BRANCH_NONE(_result, _check) do { \
+ ZVAL_BOOL(EX_VAR(opline->result.var), _result); \
+ ZEND_VM_NEXT_OPCODE_EX(_check, 1); \
+ ZEND_VM_CONTINUE(); \
+ } while (0)
#define ZEND_VM_SMART_BRANCH_TRUE() do { \
- if (EXPECTED((opline+1)->opcode == ZEND_JMPNZ)) { \
+ if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
- ZEND_VM_CONTINUE(); \
- } else if (EXPECTED((opline+1)->opcode == ZEND_JMPZ)) { \
+ } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
- ZEND_VM_CONTINUE(); \
+ } else { \
+ ZVAL_TRUE(EX_VAR(opline->result.var)); \
+ ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
} \
+ ZEND_VM_CONTINUE(); \
} while (0)
#define ZEND_VM_SMART_BRANCH_TRUE_JMPZ() do { \
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
@@ -4563,14 +4310,20 @@ static zend_never_inline int ZEND_FASTCALL zend_quick_check_constant(
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
ZEND_VM_CONTINUE(); \
} while (0)
+#define ZEND_VM_SMART_BRANCH_TRUE_NONE() do { \
+ ZVAL_TRUE(EX_VAR(opline->result.var)); \
+ ZEND_VM_NEXT_OPCODE(); \
+ } while (0)
#define ZEND_VM_SMART_BRANCH_FALSE() do { \
- if (EXPECTED((opline+1)->opcode == ZEND_JMPNZ)) { \
+ if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
- ZEND_VM_CONTINUE(); \
- } else if (EXPECTED((opline+1)->opcode == ZEND_JMPZ)) { \
+ } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
- ZEND_VM_CONTINUE(); \
+ } else { \
+ ZVAL_FALSE(EX_VAR(opline->result.var)); \
+ ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
} \
+ ZEND_VM_CONTINUE(); \
} while (0)
#define ZEND_VM_SMART_BRANCH_FALSE_JMPZ() do { \
ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
@@ -4580,15 +4333,10 @@ static zend_never_inline int ZEND_FASTCALL zend_quick_check_constant(
ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
ZEND_VM_CONTINUE(); \
} while (0)
-#else
-# define ZEND_VM_REPEATABLE_OPCODE
-# define ZEND_VM_REPEAT_OPCODE(_opcode)
-# define ZEND_VM_SMART_BRANCH(_result, _check)
-# define ZEND_VM_SMART_BRANCH_JMPZ(_result, _check)
-# define ZEND_VM_SMART_BRANCH_JMPNZ(_result, _check)
-# define ZEND_VM_SMART_BRANCH_TRUE()
-# define ZEND_VM_SMART_BRANCH_FALSE()
-#endif
+#define ZEND_VM_SMART_BRANCH_FALSE_NONE() do { \
+ ZVAL_FALSE(EX_VAR(opline->result.var)); \
+ ZEND_VM_NEXT_OPCODE(); \
+ } while (0)
#ifdef __GNUC__
# define ZEND_VM_GUARD(name) __asm__("#" #name)
@@ -4624,27 +4372,21 @@ ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode)
return zend_user_opcode_handlers[opcode];
}
-ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type)
+ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data, int type)
{
zval *ret;
switch (op_type) {
case IS_CONST:
ret = RT_CONSTANT(opline, *node);
- *should_free = NULL;
break;
case IS_TMP_VAR:
case IS_VAR:
- ret = EX_VAR(node->var);
- *should_free = ret;
- break;
case IS_CV:
ret = EX_VAR(node->var);
- *should_free = NULL;
break;
default:
ret = NULL;
- *should_free = ret;
break;
}
return ret;