diff --git a/NEWS b/NEWS index fd3aa769334..69bc6048998 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ PHP NEWS . Fixed bug GH-9890 (OpenSSL legacy providers not available on Windows). (cmb) . Fixed bug GH-9650 (Can't initialize heap: [0x000001e7]). (Michael Voříšek) . Fixed potentially undefined behavior in Windows ftok(3) emulation. (cmb) + . Fixed GH-9769 (Misleading error message for unpacking of objects). (jhdxr) - FPM: . Fixed bug GH-9959 (Solaris port event mechanism is still broken after bug diff --git a/Zend/tests/array_unpack/gh9769.phpt b/Zend/tests/array_unpack/gh9769.phpt new file mode 100644 index 00000000000..9eb8c6aea76 --- /dev/null +++ b/Zend/tests/array_unpack/gh9769.phpt @@ -0,0 +1,15 @@ +--TEST-- +Unpacking arrays in constant expression +--FILE-- +1, 'b'=>2, 'c'=>3]]; +const C = [...new ArrayObject()]; + +?> +--EXPECTF-- +Fatal error: Uncaught Error: Only arrays can be unpacked in constant expression in %sgh9769.php:5 +Stack trace: +#0 {main} + thrown in %sgh9769.php on line 5 diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 63146fc5dd2..6130d9da93b 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -488,8 +488,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) { return SUCCESS; } - /* Objects or references cannot occur in a constant expression. */ - zend_throw_error(NULL, "Only arrays and Traversables can be unpacked"); + zend_throw_error(NULL, "Only arrays can be unpacked in constant expression"); return FAILURE; }