Skip to content

Commit f5141e7

Browse files
committed
fixup! Improve error messages for invalid property access
1 parent 34dea56 commit f5141e7

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

Zend/zend_API.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ ZEND_API const char *zend_get_type_by_const(int type) /* {{{ */
133133
ZEND_API const char *zend_zval_type_name(const zval *arg) /* {{{ */
134134
{
135135
ZVAL_DEREF(arg);
136-
return zend_get_type_by_const(Z_TYPE_P(arg));
136+
137+
return Z_ISUNDEF_P(arg) ? "null" : zend_get_type_by_const(Z_TYPE_P(arg));
137138
}
138139
/* }}} */
139140

Zend/zend_execute.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,20 +622,20 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_throw_non_object_erro
622622
|| opline->opcode == ZEND_POST_DEC_OBJ) {
623623
zend_throw_error(NULL,
624624
"Attempt to increment/decrement property '%s' on %s",
625-
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
625+
ZSTR_VAL(property_name), zend_zval_type_name(object)
626626
);
627627
} else if (opline->opcode == ZEND_FETCH_OBJ_W
628628
|| opline->opcode == ZEND_FETCH_OBJ_RW
629629
|| opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG
630630
|| opline->opcode == ZEND_ASSIGN_OBJ_REF) {
631631
zend_throw_error(NULL,
632632
"Attempt to modify property '%s' on %s",
633-
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
633+
ZSTR_VAL(property_name), zend_zval_type_name(object)
634634
);
635635
} else {
636636
zend_throw_error(NULL,
637637
"Attempt to assign property '%s' on %s",
638-
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
638+
ZSTR_VAL(property_name), zend_zval_type_name(object)
639639
);
640640
}
641641
zend_tmp_string_release(tmp_property_name);
@@ -1503,9 +1503,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(z
15031503
{
15041504
zend_string *tmp_property_name;
15051505
zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
1506-
zend_error(E_WARNING, "Attempt to read property '%s' on %s",
1507-
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
1508-
);
1506+
zend_error(E_WARNING, "Attempt to read property '%s' on %s", ZSTR_VAL(property_name), zend_zval_type_name(object));
15091507
zend_tmp_string_release(tmp_property_name);
15101508
}
15111509

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,14 +1506,12 @@ static void ZEND_FASTCALL zend_jit_only_vars_by_reference(zval *arg)
15061506

15071507
static void ZEND_FASTCALL zend_jit_invalid_array_access(zval *container)
15081508
{
1509-
const char *type = Z_ISUNDEF_P(container) ? "null" : zend_zval_type_name(container);
1510-
zend_error(E_WARNING, "Trying to access array offset on value of type %s", type);
1509+
zend_error(E_WARNING, "Trying to access array offset on value of type %s", zend_zval_type_name(container));
15111510
}
15121511

15131512
static void ZEND_FASTCALL zend_jit_invalid_property_read(zval *container, char *property_name)
15141513
{
1515-
const char *type = Z_ISUNDEF_P(container) ? "null" : zend_zval_type_name(container);
1516-
zend_error(E_WARNING, "Attempt to read property '%s' on %s", property_name, type);
1514+
zend_error(E_WARNING, "Attempt to read property '%s' on %s", property_name, zend_zval_type_name(container));
15171515
}
15181516

15191517
static zval * ZEND_FASTCALL zend_jit_prepare_assign_dim_ref(zval *ref) {

0 commit comments

Comments
 (0)