Skip to content

Commit cb12bed

Browse files
inform the type in the array displacement error message.
1 parent cf523fa commit cb12bed

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
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-
Illegal offset type
14+
Illegal offset type: cannot be of type object

Zend/tests/assign_dim_obj_null_return.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ test();
7272
?>
7373
--EXPECT--
7474
Cannot add element to the array as the next element is already occupied
75-
Illegal offset type
76-
Illegal offset type
75+
Illegal offset type: cannot be of type array
76+
Illegal offset type: cannot be of type object
7777
Cannot use a scalar value as an array
7878
Cannot add element to the array as the next element is already occupied
79-
Illegal offset type
80-
Illegal offset type
79+
Illegal offset type: cannot be of type array
80+
Illegal offset type: cannot be of type object
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/bug79790.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function b($a = array()[array ()]) {
88
}
99
?>
1010
--EXPECTF--
11-
Fatal error: Uncaught TypeError: Illegal offset type in %s:%d
11+
Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %s:%d
1212
Stack trace:
1313
#0 %s(%d): b()
1414
#1 {main}

Zend/tests/bug79947.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ try {
1212
var_dump($array);
1313
?>
1414
--EXPECT--
15-
Illegal offset type
15+
Illegal offset type: cannot be of type array
1616
array(0) {
1717
}

Zend/tests/offset_array.phpt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ try {
3030
echo $e->getMessage(), "\n";
3131
}
3232

33+
try{
34+
$k = [];
35+
$arr = ['foo'];
36+
$arr[$k];
37+
}catch (Error $e){
38+
echo $e->getMessage(), "\n";
39+
}
40+
3341
echo "Done\n";
3442
?>
3543
--EXPECTF--
@@ -48,6 +56,7 @@ int(1)
4856

4957
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
5058
int(%d)
51-
Illegal offset type
52-
Illegal offset type
59+
Illegal offset type: cannot be of type object
60+
Illegal offset type: cannot be of type array
61+
Illegal offset type: cannot be of type array
5362
Done

Zend/zend_execute.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,12 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval
23132313
case IS_TRUE:
23142314
value->lval = 1;
23152315
return IS_LONG;
2316+
case IS_ARRAY:
2317+
zend_type_error("Illegal offset type: cannot be of type array");
2318+
return IS_ARRAY;
2319+
case IS_OBJECT:
2320+
zend_type_error("Illegal offset type: cannot be of type object");
2321+
return IS_OBJECT;
23162322
default:
23172323
zend_illegal_offset();
23182324
return IS_NULL;
@@ -2387,6 +2393,12 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv
23872393
case IS_TRUE:
23882394
value->lval = 1;
23892395
return IS_LONG;
2396+
case IS_ARRAY:
2397+
zend_type_error("Illegal offset type: cannot be of type array");
2398+
return IS_ARRAY;
2399+
case IS_OBJECT:
2400+
zend_type_error("Illegal offset type: cannot be of type object");
2401+
return IS_OBJECT;
23902402
default:
23912403
zend_illegal_offset();
23922404
return IS_NULL;

0 commit comments

Comments
 (0)