is already used will now result in an Error exception. Previously this was
a warning.
RFC: Part of https://wiki.php.net/rfc/engine_warnings
+ . Attempting to use an invalid type (array or object) as an array key or
+ string offset will now result in a TypeError exception. Previously this was
+ a warning.
+ RFC: Part of https://wiki.php.net/rfc/engine_warnings
- COM:
. Removed the ability to import case-insensitive constants from type
--FILE--
<?php
-$test[function(){}] = 1;
-$a{function() { }} = 1;
+try {
+ $test[function(){}] = 1;
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ $a{function() { }} = 1;
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-
-Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
-
-Warning: Illegal offset type in %s on line %d
-
-Warning: Illegal offset type in %s on line %d
+Deprecated: Array and string offset access syntax with curly braces is deprecated in %s on line %d
+Illegal offset type
+Illegal offset type
--FILE--
<?php
-var_dump(array(function() { } => 1));
+try {
+ var_dump(array(function() { } => 1));
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
-Warning: Illegal offset type in %s on line %d
-array(0) {
-}
+--EXPECT--
+Illegal offset type
echo $e->getMessage(), "\n";
}
- var_dump($array[[]] = 123);
- var_dump($array[new stdClass] = 123);
+ try {
+ var_dump($array[[]] = 123);
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
+
+ try {
+ var_dump($array[new stdClass] = 123);
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
var_dump($true[123] = 456);
try {
echo $e->getMessage(), "\n";
}
- var_dump($array[[]] += 123);
- var_dump($array[new stdClass] += 123);
+ try {
+ var_dump($array[[]] += 123);
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
+
+ try {
+ var_dump($array[new stdClass] += 123);
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
var_dump($true[123] += 456);
try {
?>
--EXPECTF--
Cannot add element to the array as the next element is already occupied
-
-Warning: Illegal offset type in %s on line %d
-NULL
-
-Warning: Illegal offset type in %s on line %d
-NULL
+Illegal offset type
+Illegal offset type
Warning: Cannot use a scalar value as an array in %s on line %d
NULL
Cannot add element to the array as the next element is already occupied
-
-Warning: Illegal offset type in %s on line %d
-NULL
-
-Warning: Illegal offset type in %s on line %d
-NULL
+Illegal offset type
+Illegal offset type
Warning: Cannot use a scalar value as an array in %s on line %d
NULL
--TEST--
Bug #36303 (foreach on error_zval produces segfault)
+--XFAIL--
+TODO: ERROR zval still possible?
--FILE--
<?php
$x = [];
--TEST--
Bug #52237 (Crash when passing the reference of the property of a non-object)
+--XFAIL--
+TODO: ERROR zval still possible?
--FILE--
<?php
$data = [];
?>
--EXPECTF--
-Fatal error: Uncaught Error: Illegal offset type in %s:%d
+Fatal error: Uncaught TypeError: Illegal offset type in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
var_dump($arr[$fp]);
$obj = new stdClass;
-var_dump($arr[$obj]);
+try {
+ var_dump($arr[$obj]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
$arr1 = Array(1,2,3);
-var_dump($arr[$arr1]);
+try {
+ var_dump($arr[$arr1]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
echo "Done\n";
?>
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
int(%d)
-
-Warning: Illegal offset type in %s on line %d
-NULL
-
-Warning: Illegal offset type in %s on line %d
-NULL
+Illegal offset type
+Illegal offset type
Done
var_dump($str[FALSE]);
$fp = fopen(__FILE__, "r");
-var_dump($str[$fp]);
+try {
+ var_dump($str[$fp]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
$obj = new stdClass;
-var_dump($str[$obj]);
+try {
+ var_dump($str[$obj]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
$arr = Array(1,2,3);
-var_dump($str[$arr]);
+try {
+ var_dump($str[$arr]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
echo "Done\n";
?>
Notice: String offset cast occurred in %s on line %d
string(1) "S"
-
-Warning: Illegal offset type in %s on line %d
-string(1) "%s"
-
-Warning: Illegal offset type in %s on line %d
+Illegal offset type
Notice: Object of class stdClass could not be converted to int in %s on line %d
-string(1) "%s"
-
-Warning: Illegal offset type in %s on line %d
-string(1) "i"
+Illegal offset type
+Illegal offset type
Done
result = zend_hash_index_update(ht, zend_dval_to_lval(Z_DVAL_P(key)), value);
break;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
result = NULL;
}
zend_hash_index_update(Z_ARRVAL_P(result), Z_RES_HANDLE_P(offset), expr);
break;
default:
- zend_throw_error(NULL, "Illegal offset type");
+ zend_type_error("Illegal offset type");
return FAILURE;
}
return SUCCESS;
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)
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;
}
}
key = ZSTR_EMPTY_ALLOC();
ZEND_VM_C_GOTO(str_index_dim);
} else {
- zend_error(E_WARNING, "Illegal offset type in unset");
+ zend_type_error("Illegal offset type in unset");
}
break;
} else if (Z_ISREF_P(container)) {
key = ZSTR_EMPTY_ALLOC();
goto str_index_dim;
} else {
- zend_error(E_WARNING, "Illegal offset type in unset");
+ zend_type_error("Illegal offset type in unset");
}
break;
} else if (Z_ISREF_P(container)) {
key = ZSTR_EMPTY_ALLOC();
goto str_index_dim;
} else {
- zend_error(E_WARNING, "Illegal offset type in unset");
+ zend_type_error("Illegal offset type in unset");
}
break;
} else if (Z_ISREF_P(container)) {
key = ZSTR_EMPTY_ALLOC();
goto str_index_dim;
} else {
- zend_error(E_WARNING, "Illegal offset type in unset");
+ zend_type_error("Illegal offset type in unset");
}
break;
} else if (Z_ISREF_P(container)) {
key = ZSTR_EMPTY_ALLOC();
goto str_index_dim;
} else {
- zend_error(E_WARNING, "Illegal offset type in unset");
+ zend_type_error("Illegal offset type in unset");
}
break;
} else if (Z_ISREF_P(container)) {
key = ZSTR_EMPTY_ALLOC();
goto str_index_dim;
} else {
- zend_error(E_WARNING, "Illegal offset type in unset");
+ zend_type_error("Illegal offset type in unset");
}
break;
} else if (Z_ISREF_P(container)) {
key = ZSTR_EMPTY_ALLOC();
goto str_index_dim;
} else {
- zend_error(E_WARNING, "Illegal offset type in unset");
+ zend_type_error("Illegal offset type in unset");
}
break;
} else if (Z_ISREF_P(container)) {
hval = 1;
goto num_index;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
ZVAL_NULL(result);
return;
}
hval = 1;
goto num_index;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
ZVAL_NULL(result);
return;
}
hval = 1;
goto num_index;
default:
- zend_error(E_WARNING, "Illegal offset type in isset or empty");
+ zend_type_error("Illegal offset type in isset or empty");
return 0;
}
hval = 1;
goto num_index;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
return NULL;
}
hval = 1;
goto num_index;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
return NULL;
}
dim = Z_REFVAL_P(dim);
goto try_string_offset;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
break;
}
dim = Z_REFVAL_P(dim);
goto try_string_offset;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
break;
}
dim = Z_REFVAL_P(dim);
goto try_again;
default:
- zend_error(E_WARNING, "Illegal offset type");
+ zend_type_error("Illegal offset type");
break;
}
$array[0][1] = 1;
var_dump($array);
- $array[function() {}] = 2;
+ try {
+ $array[function() {}] = 2;
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
var_dump($array);
$array2[][] = 3;
int(1)
}
}
-
-Warning: Illegal offset type in %sassign_dim_002.php on line 51
+Illegal offset type
array(1) {
[0]=>
array(2) {
}
}
-Warning: Cannot use a scalar value as an array in %sassign_dim_002.php on line 61
+Warning: Cannot use a scalar value as an array in %sassign_dim_002.php on line 65
int(1)
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
var_dump(session_start());
- $_SESSION[$input] = "Hello World!";
+ try {
+ $_SESSION[$input] = "Hello World!";
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
var_dump(session_encode());
var_dump(session_destroy());
$iterator++;
-- Iteration 21 --
bool(true)
-
-Warning: Illegal offset type in %s on line 82
+Illegal offset type
bool(false)
bool(true)
yield new stdClass => 5;
}
-var_dump(iterator_to_array(gen()));
+try {
+ var_dump(iterator_to_array(gen()));
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
-Warning: Illegal offset type in %s on line %d
-
-Warning: Illegal offset type in %s on line %d
-array(4) {
- ["foo"]=>
- int(0)
- [1]=>
- int(1)
- [2]=>
- int(2)
- [""]=>
- int(3)
-}
+--EXPECT--
+Illegal offset type
array("hello", $heredoc => "string"), // heredoc
// array with object, unset variable and resource variable
-/*10*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
+/*10*/ array(@$unset_var => "hello", $fp => 'resource'),
// array with mixed keys
-/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2,
+/*11*/ array('hello' => 1, "fruit" => 2.2,
$fp => 'resource', 133 => "int", 444.432 => "float",
@$unset_var => "unset", $heredoc => "heredoc")
);
// array to be passsed to $arr2 argument
$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
"\tHello" => 111, 2.2, 'color', "Hello world" => "string",
- "pen\n" => 33, new classA() => 11, 133 => "int");
+ "pen\n" => 33, 133 => "int");
// loop through each sub-array within $arrays to check the behavior of array_combine()
// same arrays are passed to both $keys and $values
--EXPECTF--
*** Testing array_combine() : assoc array with diff keys to both $keys and $values argument ***
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-
-Warning: Illegal offset type in %s on line %d
-- Iteration 1 --
array(0) {
}
+++ /dev/null
---TEST--
-Test array_keys() function (error conditions)
---FILE--
-<?php
-
-echo "\n*** Testing error conditions ***\n";
-try {
- var_dump(array_keys(new stdclass)); // object
-} catch (TypeError $e) {
- echo $e->getMessage(), "\n";
-}
-var_dump(array_keys(array(1,2,3, new stdClass => array()))); // (W)illegal offset
-
-echo "Done\n";
-?>
---EXPECTF--
-*** Testing error conditions ***
-array_keys() expects parameter 1 to be array, object given
-
-Warning: Illegal offset type in %s on line %d
-array(3) {
- [0]=>
- int(0)
- [1]=>
- int(1)
- [2]=>
- int(2)
-}
-Done
array("hello", $heredoc => "string"), // heredoc
// array with object, unset variable and resource variable
- array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
+ array(@$unset_var => "hello", $fp => 'resource'),
// array with mixed values
-/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2,
+/*11*/ array('hello' => 1, "fruit" => 2.2,
$fp => 'resource', 133 => "int", 444.432 => "float",
@$unset_var => "unset", $heredoc => "heredoc")
);
--EXPECTF--
*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-- Iteration 1 --
array(0) {
array("hello", $heredoc => array("heredoc", 'string'), "string"),
// array with object, unset variable and resource variable
-/*8*/ array(new classA() => 11, @$unset_var => array("unset"), $fp => 'resource', 11, "hello")
+/*8*/ array(@$unset_var => array("unset"), $fp => 'resource', 11, "hello")
);
// initialise the second array
--EXPECTF--
*** Testing array_merge_recursive() : assoc. array with diff. keys to $arr1 argument ***
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-- Iteration 1 --
-- With default argument --
array("hello", $heredoc => "string"), // heredoc
// array with object, unset variable and resource variable
- array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
+ array(@$unset_var => "hello", $fp => 'resource'),
// array with mixed values
-/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, $fp => 'resource', 133 => "int", 444.432 => "float", @$unset_var => "unset", $heredoc => "heredoc")
+/*11*/ array('hello' => 1, "fruit" => 2.2, $fp => 'resource', 133 => "int", 444.432 => "float", @$unset_var => "unset", $heredoc => "heredoc")
);
// loop through the various elements of $arrays to test array_reverse()
--EXPECTF--
*** Testing array_reverse() : usage variations ***
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-- Iteration 1 --
- default argument -
array("hello", $heredoc => "string", "string"),
// array with object, unset variable and resource variable
-/*8*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource', 11, "hello"),
+/*8*/ array(@$unset_var => "hello", $fp => 'resource', 11, "hello"),
);
// loop through each sub-array of $inputs to check the behavior of array_unique()
--EXPECTF--
*** Testing array_unique() : assoc. array with diff. keys passed to $input argument ***
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-- Iteration 1 --
array(1) {
array("hello", $heredoc => "string"), // heredoc
// array with object, unset variable and resource variable
- array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
+ array(@$unset_var => "hello", $fp => 'resource'),
// array with mixed keys
-/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2,
+/*11*/ array('hello' => 1, "fruit" => 2.2,
$fp => 'resource', 133 => "int", 444.432 => "float",
@$unset_var => "unset", $heredoc => "heredoc")
);
--EXPECTF--
*** Testing array_unshift() : associative array with different keys ***
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-Warning: Illegal offset type in %s on line %d
-
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-- Iteration 1 --
int(1)
echo "====test7====\n";
$ar = array();
$ar[$o->__toString()] = "ERROR";
-echo $ar[$o];
+try {
+ echo $ar[$o];
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
echo "====test8====\n";
var_dump(trim($o));
?>
====DONE====
---EXPECTF--
+--EXPECT--
====test1====
test1 Object
(
Converted
====test7====
test2::__toString()
-
-Warning: Illegal offset type in %s on line %d
+Illegal offset type
====test8====
test2::__toString()
string(9) "Converted"
test2::__toString()
Converted
====test10====
-object(test3)#1 (0) {
+object(test3)#2 (0) {
}
test3::__toString()
Method test3::__toString() must return a string value