Skip to content

Inform type in messsage: 'Illegal offset type' #10504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/036.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ try {

?>
--EXPECT--
Illegal offset type
Cannot access offset of type object on array
2 changes: 1 addition & 1 deletion Zend/tests/038.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ try {

?>
--EXPECT--
Illegal offset type
Cannot access offset of type object on array
8 changes: 4 additions & 4 deletions Zend/tests/assign_dim_obj_null_return.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ test();
?>
--EXPECT--
Cannot add element to the array as the next element is already occupied
Illegal offset type
Illegal offset type
Cannot access offset of type array on array
Cannot access offset of type object on array
Cannot use a scalar value as an array
Cannot add element to the array as the next element is already occupied
Illegal offset type
Illegal offset type
Cannot access offset of type array on array
Cannot access offset of type object on array
Cannot use a scalar value as an array
Attempt to assign property "foo" on true
Attempt to assign property "foo" on true
2 changes: 1 addition & 1 deletion Zend/tests/bug79790.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function b($a = array()[array ()]) {
}
?>
--EXPECTF--
Fatal error: Uncaught TypeError: Illegal offset type in %s:%d
Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %s:%d
Stack trace:
#0 %s(%d): b()
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug79947.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ try {
var_dump($array);
?>
--EXPECT--
Illegal offset type
Cannot access offset of type array on array
array(0) {
}
2 changes: 1 addition & 1 deletion Zend/tests/bug80781.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (isset($array[$data]) or getPlugin($data)) {

?>
--EXPECTF--
Fatal error: Uncaught TypeError: Illegal offset type in isset or empty in %s:%d
Fatal error: Uncaught TypeError: Cannot access offset of type array in isset or empty in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const C2 = [C1, [] => 1];

?>
--EXPECTF--
Fatal error: Uncaught TypeError: Illegal offset type in %s:%d
Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/gh8821.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ new Bravo();

?>
--EXPECTF--
Fatal error: Uncaught TypeError: Illegal offset type in %sgh8821.php:8
Fatal error: Uncaught TypeError: Cannot access offset of type object on array in %sgh8821.php:8
Stack trace:
#0 %sgh8821.php(11): [constant expression]()
#1 {main}
Expand Down
6 changes: 3 additions & 3 deletions Zend/tests/illegal_offset_unset_isset_empty.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ try {

?>
--EXPECT--
Illegal offset type in unset
Illegal offset type in isset or empty
Illegal offset type in isset or empty
Cannot access offset of type array in unset
Cannot access offset of type array in isset or empty
Cannot access offset of type array in isset or empty
2 changes: 1 addition & 1 deletion Zend/tests/init_array_illegal_offset_type.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ try {
}
?>
--EXPECT--
Illegal offset type
Cannot access offset of type object on array
4 changes: 2 additions & 2 deletions Zend/tests/isset_array.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ bool(false)

Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
bool(false)
Illegal offset type in isset or empty
Illegal offset type in isset or empty
Cannot access offset of type array in isset or empty
Cannot access offset of type object in isset or empty
4 changes: 2 additions & 2 deletions Zend/tests/offset_array.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ int(1)

Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
int(%d)
Illegal offset type
Illegal offset type
Cannot access offset of type object on array
Cannot access offset of type array on array
Done
12 changes: 11 additions & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_en
}
/* }}} */

ZEND_API ZEND_COLD void zend_illegal_array_offset(const zval *offset)
{
zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset)));
}

ZEND_API ZEND_COLD void zend_illegal_empty_or_isset_offset(const zval *offset)
{
zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset)));
}

ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...) /* {{{ */
{
va_list va;
Expand Down Expand Up @@ -2074,7 +2084,7 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
result = zend_hash_index_update(ht, zend_dval_to_lval_safe(Z_DVAL_P(key)), value);
break;
default:
zend_type_error("Illegal offset type");
zend_illegal_array_offset(key);
result = NULL;
}

Expand Down
22 changes: 16 additions & 6 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,9 +1466,19 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v
zend_throw_error(NULL, "Cannot use object as array");
}

static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(void)
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_unset_offset(const zval *offset)
{
zend_type_error("Illegal offset type");
zend_type_error("Cannot access offset of type %s in unset", zend_get_type_by_const(Z_TYPE_P(offset)));
}

static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset)
{
zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset)));
}

static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_empty_or_isset_offset(const zval *offset)
{
zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset)));
}

static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset)
Expand Down Expand Up @@ -2340,7 +2350,7 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval
value->lval = 1;
return IS_LONG;
default:
zend_illegal_offset();
zend_illegal_array_offset(dim);
return IS_NULL;
}
}
Expand Down Expand Up @@ -2414,7 +2424,7 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv
value->lval = 1;
return IS_LONG;
default:
zend_illegal_offset();
zend_illegal_array_offset(dim);
return IS_NULL;
}
}
Expand Down Expand Up @@ -2873,7 +2883,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable
ZVAL_UNDEFINED_OP2();
goto str_idx;
} else {
zend_type_error("Illegal offset type in isset or empty");
zend_illegal_empty_or_isset_offset(offset);
return NULL;
}
}
Expand Down Expand Up @@ -2996,7 +3006,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable
str = ZSTR_EMPTY_ALLOC();
goto str_key;
} else {
zend_illegal_offset();
zend_illegal_array_offset(key);
return 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -6073,7 +6073,7 @@ ZEND_VM_C_LABEL(num_index):
str = ZSTR_EMPTY_ALLOC();
ZEND_VM_C_GOTO(str_index);
} else {
zend_illegal_offset();
zend_illegal_array_offset(offset);
zval_ptr_dtor_nogc(expr_ptr);
}
FREE_OP2();
Expand Down Expand Up @@ -6589,7 +6589,7 @@ ZEND_VM_C_LABEL(num_index_dim):
key = ZSTR_EMPTY_ALLOC();
ZEND_VM_C_GOTO(str_index_dim);
} else {
zend_type_error("Illegal offset type in unset");
zend_illegal_unset_offset(offset);
}
break;
} else if (Z_ISREF_P(container)) {
Expand Down
Loading