From 40b8105cca1fa3cc4b696b059308b6d0f2827fa8 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 28 Sep 2016 23:05:21 +0200 Subject: [PATCH] Fix the constant array case as well --- Zend/tests/array_literal_next_element_error.phpt | 9 +++++++++ Zend/zend_compile.c | 7 +++++-- Zend/zend_compile.h | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Zend/tests/array_literal_next_element_error.phpt b/Zend/tests/array_literal_next_element_error.phpt index 59ffeb02c7..8b4af3cadd 100644 --- a/Zend/tests/array_literal_next_element_error.phpt +++ b/Zend/tests/array_literal_next_element_error.phpt @@ -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) +} diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5b67ef8295..d3bec3714e 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5929,7 +5929,7 @@ void zend_do_add_array_element(znode *result, const znode *expr, const znode *of } /* }}} */ -void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr) /* {{{ */ +void zend_do_add_static_array_element(zval *result, zval *offset, zval *expr) /* {{{ */ { if (offset) { switch (Z_TYPE_P(offset)) { @@ -5952,7 +5952,10 @@ void zend_do_add_static_array_element(zval *result, zval *offset, const zval *ex break; } } else { - zend_hash_next_index_insert(Z_ARRVAL_P(result), &expr, sizeof(zval *), NULL); + if (zend_hash_next_index_insert(Z_ARRVAL_P(result), &expr, sizeof(zval *), NULL) == FAILURE) { + zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied"); + zval_ptr_dtor(&expr); + } } } /* }}} */ diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index e7a73252ee..a0955e34fe 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -598,7 +598,7 @@ void zend_do_shell_exec(znode *result, const znode *cmd TSRMLS_DC); void zend_do_init_array(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC); void zend_do_add_array_element(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC); -void zend_do_add_static_array_element(zval *result, zval *offset, const zval *expr); +void zend_do_add_static_array_element(zval *result, zval *offset, zval *expr); void zend_do_list_init(TSRMLS_D); void zend_do_list_end(znode *result, znode *expr TSRMLS_DC); void zend_do_add_list_element(const znode *element TSRMLS_DC); -- 2.40.0