the value into an object (if it was null, false or an empty string) or
ignored the write altogether (in all other cases).
RFC: Part of https://wiki.php.net/rfc/engine_warnings
+ . Attempting to append an element to an array for which the PHP_INT_MAX key
+ 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
- COM:
. Removed the ability to import case-insensitive constants from type
<?php
$i = PHP_INT_MAX;
-$array = [$i => 42, new stdClass];
-var_dump($array);
-
-const FOO = [PHP_INT_MAX => 42, "foo"];
-var_dump(FOO);
-
-?>
---EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-array(1) {
- [%d]=>
- int(42)
+try {
+ $array = [$i => 42, new stdClass];
+ var_dump($array);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
}
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-array(1) {
- [%d]=>
- int(42)
+function test($x = [PHP_INT_MAX => 42, "foo"]) {}
+try {
+ test();
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
}
+
+?>
+--EXPECT--
+Cannot add element to the array as the next element is already occupied
+Cannot add element to the array as the next element is already occupied
<?php
$arr = [1, 2, 3];
-var_dump([PHP_INT_MAX-1 => 0, ...$arr]);
-
-var_dump([PHP_INT_MAX-1 => 0, ...[1, 2, 3]]);
-
-const ARR = [1, 2, 3];
-const ARR2 = [PHP_INT_MAX-1 => 0, ...ARR];
-var_dump(ARR2);
-
-?>
---EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-array(2) {
- [9223372036854775806]=>
- int(0)
- [9223372036854775807]=>
- int(1)
+try {
+ var_dump([PHP_INT_MAX-1 => 0, ...$arr]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
}
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-array(2) {
- [9223372036854775806]=>
- int(0)
- [9223372036854775807]=>
- int(1)
+try {
+ var_dump([PHP_INT_MAX-1 => 0, ...[1, 2, 3]]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
}
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-array(2) {
- [9223372036854775806]=>
- int(0)
- [9223372036854775807]=>
- int(1)
+const ARR = [1, 2, 3];
+function test($x = [PHP_INT_MAX-1 => 0, ...ARR]) {}
+try {
+ test();
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
}
+
+?>
+--EXPECT--
+Cannot add element to the array as the next element is already occupied
+Cannot add element to the array as the next element is already occupied
+Cannot add element to the array as the next element is already occupied
$array = [PHP_INT_MAX => 42];
$true = true;
- var_dump($array[] = 123);
+ try {
+ var_dump($array[] = 123);
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
+
var_dump($array[[]] = 123);
var_dump($array[new stdClass] = 123);
var_dump($true[123] = 456);
- var_dump($array[] += 123);
+ try {
+ var_dump($array[] += 123);
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
+
var_dump($array[[]] += 123);
var_dump($array[new stdClass] += 123);
var_dump($true[123] += 456);
?>
--EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied 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: Cannot use a scalar value as an array in %s on line %d
NULL
-
-Warning: Cannot add element to the array as the next element is already occupied 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
$var = 24;
$arr = [PHP_INT_MAX => "foo"];
-var_dump($arr[] =& $var);
+try {
+ var_dump($arr[] =& $var);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
var_dump(count($arr));
-var_dump($arr[] =& val());
+try {
+ var_dump($arr[] =& val());
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
var_dump(count($arr));
?>
---EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-NULL
+--EXPECT--
+Cannot add element to the array as the next element is already occupied
int(1)
-
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-NULL
+Cannot add element to the array as the next element is already occupied
int(1)
Bug #36303 (foreach on error_zval produces segfault)
--FILE--
<?php
-$x=[PHP_INT_MAX=>"test"];
-foreach ($x[] as &$v) {
+$x = [];
+foreach ($x[[]] as &$v) {
}
echo "ok\n";
?>
--EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
+Warning: Illegal offset type in %s on line %d
Warning: Invalid argument supplied for foreach() in %s on line %d
ok
<?php
$arr[PHP_INT_MAX] = 1;
-$arr[] = 2;
+try {
+ $arr[] = 2;
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
var_dump($arr);
?>
--EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied in %s on line 4
+Cannot add element to the array as the next element is already occupied
array(1) {
[%d]=>
int(1)
Bug #52237 (Crash when passing the reference of the property of a non-object)
--FILE--
<?php
-$data = [PHP_INT_MAX => 'test'];
-preg_match('//', '', $data[]);
+$data = [];
+preg_match('//', '', $data[[]]);
var_dump(count($data));
?>
--EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
-int(1)
+Warning: Illegal offset type in %s on line %d
+int(0)
c1::$a1[] = 1;
c1::$a2[] = 1;
-c1::$a3[] = 1;
+try {
+ c1::$a3[] = 1;
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
var_dump(c1::$a1);
var_dump(c1::$a2);
var_dump(c1::$a3);
?>
--EXPECTF--
-Warning: Cannot add element to the array as the next element is already occupied in %sbug69017.php on line %d
+Cannot add element to the array as the next element is already occupied
array(2) {
[1]=>
string(3) "one"
--TEST--
Bug #71841 (EG(error_zval) is not handled well)
---INI--
-error_reporting=0
--FILE--
<?php
$z = unserialize('O:1:"A":0:{}');
-var_dump($z->e.=0);
-var_dump(++$z->x);
-var_dump($z->y++);
+@var_dump($z->e.=0);
+@var_dump(++$z->x);
+@var_dump($z->y++);
$y = array(PHP_INT_MAX => 0);
-var_dump($y[] .= 0);
-var_dump(++$y[]);
-var_dump($y[]++);
+try {
+ var_dump($y[] .= 0);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump(++$y[]);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump($y[]++);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
?>
--EXPECT--
NULL
NULL
NULL
-NULL
-NULL
-NULL
+Cannot add element to the array as the next element is already occupied
+Cannot add element to the array as the next element is already occupied
+Cannot add element to the array as the next element is already occupied
switch (Z_TYPE_P(offset)) {
case IS_UNDEF:
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), expr)) {
- zend_error(E_WARNING,
+ zend_throw_error(NULL,
"Cannot add element to the array as the next element is already occupied");
- zval_ptr_dtor_nogc(expr);
+ return FAILURE;
}
break;
case IS_STRING:
return FAILURE;
} else {
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), val)) {
- zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
- break;
+ zend_throw_error(NULL,
+ "Cannot add element to the array as the next element is already occupied");
+ return FAILURE;
}
Z_TRY_ADDREF_P(val);
}
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void)
{
- zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
}
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
| SET_Z_TYPE_INFO FP + r0, IS_NULL
|1:
|.if X64WIN
- | mov CARG1, E_WARNING
+ | xor CARG1, CARG1
| LOAD_ADDR CARG2, "Cannot add element to the array as the next element is already occupied"
- | EXT_CALL zend_error, r0
+ | EXT_CALL zend_throw_error, r0
| add r4, 0x28
|.elif X64
- | mov CARG1, E_WARNING
+ | xor CARG1, CARG1
| LOAD_ADDR CARG2, "Cannot add element to the array as the next element is already occupied"
- | EXT_CALL zend_error, r0
+ | EXT_CALL zend_throw_error, r0
| add r4, 8
|.else
| sub r4, 8
| push "Cannot add element to the array as the next element is already occupied"
- | push E_WARNING
- | EXT_CALL zend_error, r0
+ | push 0
+ | EXT_CALL zend_throw_error, r0
| add r4, 28
|.endif
| ret
| jz >1
|.cold_code
|1:
- | // zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ | // zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
| CANNOT_ADD_ELEMENT opline
| //ZEND_VM_C_GOTO(assign_dim_op_ret_null);
| jmp >9
| jz >1
|.cold_code
|1:
- | // zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ | // zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
| CANNOT_ADD_ELEMENT opline
| //ZEND_VM_C_GOTO(assign_dim_op_ret_null);
| jmp >9
function foo3() {
$array = array(PHP_INT_MAX => "dummy");
- $array[] = array();
+ try {
+ $array[] = array();
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
$array = new ArrayObject();
$array[index()] = 1;
array(0) {
}
}
-
-Warning: Cannot add element to the array as the next element is already occupied in %sassign_dim_002.php on line 22
-object(ArrayObject)#1 (1) {
+Cannot add element to the array as the next element is already occupied
+object(ArrayObject)#%d (1) {
["storage":"ArrayObject":private]=>
array(2) {
[2]=>
}
}
-Warning: Illegal offset type in %sassign_dim_002.php on line 47
+Warning: Illegal offset type in %sassign_dim_002.php on line 51
array(1) {
[0]=>
array(2) {
}
}
-Warning: Cannot use a scalar value as an array in %sassign_dim_002.php on line 57
+Warning: Cannot use a scalar value as an array in %sassign_dim_002.php on line 61
int(1)