Skip to content

Commit 5c73b46

Browse files
committed
Use common function for container offset type errors
1 parent 641fe23 commit 5c73b46

21 files changed

+84
-112
lines changed

Zend/tests/036.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ try {
1111

1212
?>
1313
--EXPECT--
14-
Cannot access offset of type object on array
14+
Cannot access offset of type Closure on array

Zend/tests/038.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ try {
1111

1212
?>
1313
--EXPECT--
14-
Cannot access offset of type object on array
14+
Cannot access offset of type Closure on array

Zend/tests/assign_dim_obj_null_return.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ test();
7373
--EXPECT--
7474
Cannot add element to the array as the next element is already occupied
7575
Cannot access offset of type array on array
76-
Cannot access offset of type object on array
76+
Cannot access offset of type stdClass on array
7777
Cannot use a scalar value as an array
7878
Cannot add element to the array as the next element is already occupied
7979
Cannot access offset of type array on array
80-
Cannot access offset of type object on array
80+
Cannot access offset of type stdClass on array
8181
Cannot use a scalar value as an array
8282
Attempt to assign property "foo" on true
8383
Attempt to assign property "foo" on true

Zend/tests/gh8821.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ new Bravo();
1515

1616
?>
1717
--EXPECTF--
18-
Fatal error: Uncaught TypeError: Cannot access offset of type object on array in %sgh8821.php:8
18+
Fatal error: Uncaught TypeError: Cannot access offset of type Alpha on array in %sgh8821.php:8
1919
Stack trace:
2020
#0 %sgh8821.php(11): [constant expression]()
2121
#1 {main}

Zend/tests/init_array_illegal_offset_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ try {
1212
}
1313
?>
1414
--EXPECT--
15-
Cannot access offset of type object on array
15+
Cannot access offset of type stdClass on array

Zend/tests/offset_array.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ int(1)
4848

4949
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
5050
int(%d)
51-
Cannot access offset of type object on array
51+
Cannot access offset of type stdClass on array
5252
Cannot access offset of type array on array
5353
Done

Zend/zend.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,16 @@ ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const c
17281728
}
17291729
/* }}} */
17301730

1731+
ZEND_API ZEND_COLD void zend_illegal_container_offset(const char *container, const zval *offset)
1732+
{
1733+
zend_type_error("Cannot access offset of type %s on %s", zend_zval_type_name(offset), container);
1734+
}
1735+
1736+
ZEND_API ZEND_COLD void zend_illegal_empty_or_isset_offset(const zval *offset)
1737+
{
1738+
zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset)));
1739+
}
1740+
17311741
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) /* {{{ */
17321742
{
17331743
va_list va;

Zend/zend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const c
356356
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
357357
ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
358358
ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
359+
ZEND_API ZEND_COLD void zend_illegal_container_offset(const char *container, const zval *offset);
360+
ZEND_API ZEND_COLD void zend_illegal_empty_or_isset_offset(const zval *offset);
359361

360362
ZEND_COLD void zenderror(const char *error);
361363

Zend/zend_API.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,6 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_en
407407
}
408408
/* }}} */
409409

410-
ZEND_API ZEND_COLD void zend_illegal_array_offset(const zval *offset)
411-
{
412-
zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset)));
413-
}
414-
415-
ZEND_API ZEND_COLD void zend_illegal_empty_or_isset_offset(const zval *offset)
416-
{
417-
zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset)));
418-
}
419-
420410
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...) /* {{{ */
421411
{
422412
va_list va;
@@ -2084,7 +2074,7 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
20842074
result = zend_hash_index_update(ht, zend_dval_to_lval_safe(Z_DVAL_P(key)), value);
20852075
break;
20862076
default:
2087-
zend_illegal_array_offset(key);
2077+
zend_illegal_container_offset("array", key);
20882078
result = NULL;
20892079
}
20902080

Zend/zend_execute.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,21 +1471,6 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_unset_offset(
14711471
zend_type_error("Cannot access offset of type %s in unset", zend_get_type_by_const(Z_TYPE_P(offset)));
14721472
}
14731473

1474-
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset)
1475-
{
1476-
zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset)));
1477-
}
1478-
1479-
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_empty_or_isset_offset(const zval *offset)
1480-
{
1481-
zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset)));
1482-
}
1483-
1484-
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset)
1485-
{
1486-
zend_type_error("Cannot access offset of type %s on string", zend_zval_type_name(offset));
1487-
}
1488-
14891474
static zend_never_inline void zend_assign_to_object_dim(zend_object *obj, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)
14901475
{
14911476
obj->handlers->write_dimension(obj, dim, value);
@@ -1611,7 +1596,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type
16111596
}
16121597
return offset;
16131598
}
1614-
zend_illegal_string_offset(dim);
1599+
zend_illegal_container_offset("string", dim);
16151600
return 0;
16161601
}
16171602
case IS_UNDEF:
@@ -1627,7 +1612,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type
16271612
dim = Z_REFVAL_P(dim);
16281613
goto try_again;
16291614
default:
1630-
zend_illegal_string_offset(dim);
1615+
zend_illegal_container_offset("string", dim);
16311616
return 0;
16321617
}
16331618

@@ -2350,7 +2335,7 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval
23502335
value->lval = 1;
23512336
return IS_LONG;
23522337
default:
2353-
zend_illegal_array_offset(dim);
2338+
zend_illegal_container_offset("array", dim);
23542339
return IS_NULL;
23552340
}
23562341
}
@@ -2424,7 +2409,7 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv
24242409
value->lval = 1;
24252410
return IS_LONG;
24262411
default:
2427-
zend_illegal_array_offset(dim);
2412+
zend_illegal_container_offset("array", dim);
24282413
return IS_NULL;
24292414
}
24302415
}
@@ -2722,7 +2707,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
27222707
ZVAL_NULL(result);
27232708
return;
27242709
}
2725-
zend_illegal_string_offset(dim);
2710+
zend_illegal_container_offset("string", dim);
27262711
ZVAL_NULL(result);
27272712
return;
27282713
}
@@ -2761,7 +2746,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
27612746
dim = Z_REFVAL_P(dim);
27622747
goto try_string_offset;
27632748
default:
2764-
zend_illegal_string_offset(dim);
2749+
zend_illegal_container_offset("string", dim);
27652750
ZVAL_NULL(result);
27662751
return;
27672752
}
@@ -3006,7 +2991,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable
30062991
str = ZSTR_EMPTY_ALLOC();
30072992
goto str_key;
30082993
} else {
3009-
zend_illegal_array_offset(key);
2994+
zend_illegal_container_offset("array", key);
30102995
return 0;
30112996
}
30122997
}

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6069,7 +6069,7 @@ ZEND_VM_C_LABEL(num_index):
60696069
str = ZSTR_EMPTY_ALLOC();
60706070
ZEND_VM_C_GOTO(str_index);
60716071
} else {
6072-
zend_illegal_array_offset(offset);
6072+
zend_illegal_container_offset("array", offset);
60736073
zval_ptr_dtor_nogc(expr_ptr);
60746074
}
60756075
FREE_OP2();

Zend/zend_vm_execute.h

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)