Merge branch 'PHP-7.1'

This commit is contained in:
Nikita Popov 2016-09-28 23:23:01 +02:00
commit 6ec5816899
4 changed files with 38 additions and 2 deletions

View File

@ -7,6 +7,9 @@ $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
@ -14,3 +17,9 @@ array(1) {
[%d]=>
int(42)
}
Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
array(1) {
[%d]=>
int(42)
}

View File

@ -0,0 +1,15 @@
--TEST--
Constexpr arrays should be able to handle resource keys
--FILE--
<?php
const FOO = [STDIN => 42];
var_dump(FOO);
?>
--EXPECTF--
Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
array(1) {
[%d]=>
int(42)
}

View File

@ -181,7 +181,11 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
{
switch (Z_TYPE_P(offset)) {
case IS_UNDEF:
zend_hash_next_index_insert(Z_ARRVAL_P(result), expr);
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), expr)) {
zend_error(E_WARNING,
"Cannot add element to the array as the next element is already occupied");
zval_ptr_dtor(expr);
}
break;
case IS_STRING:
zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(offset), expr);
@ -202,6 +206,10 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
case IS_DOUBLE:
zend_hash_index_update(Z_ARRVAL_P(result), zend_dval_to_lval(Z_DVAL_P(offset)), expr);
break;
case IS_RESOURCE:
zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(offset), Z_RES_HANDLE_P(offset));
zend_hash_index_update(Z_ARRVAL_P(result), Z_RES_HANDLE_P(offset), expr);
break;
default:
zend_throw_error(NULL, "Illegal offset type");
return FAILURE;

View File

@ -6628,7 +6628,11 @@ static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
break;
}
} else {
zend_hash_next_index_insert(Z_ARRVAL_P(result), value);
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), value)) {
zval_ptr_dtor_nogc(value);
zval_ptr_dtor(result);
return 0;
}
}
}