Skip to content

Commit 6b1f4c5

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-9769: Misleading error message for unpacking of objects
2 parents 1316a5b + 93592ea commit 6b1f4c5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PHP NEWS
1010
. Fixed bug GH-9890 (OpenSSL legacy providers not available on Windows). (cmb)
1111
. Fixed bug GH-9650 (Can't initialize heap: [0x000001e7]). (Michael Voříšek)
1212
. Fixed potentially undefined behavior in Windows ftok(3) emulation. (cmb)
13+
. Fixed GH-9769 (Misleading error message for unpacking of objects). (jhdxr)
1314

1415
- FPM:
1516
. Fixed bug GH-9959 (Solaris port event mechanism is still broken after bug

Zend/tests/array_unpack/gh9769.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Unpacking arrays in constant expression
3+
--FILE--
4+
<?php
5+
6+
const A = [...[1, 2, 3]];
7+
const B = [...['a'=>1, 'b'=>2, 'c'=>3]];
8+
const C = [...new ArrayObject()];
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught Error: Only arrays can be unpacked in constant expression in %sgh9769.php:5
13+
Stack trace:
14+
#0 {main}
15+
thrown in %sgh9769.php on line 5

Zend/zend_ast.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) {
488488
return SUCCESS;
489489
}
490490

491-
/* Objects or references cannot occur in a constant expression. */
492-
zend_throw_error(NULL, "Only arrays and Traversables can be unpacked");
491+
zend_throw_error(NULL, "Only arrays can be unpacked in constant expression");
493492
return FAILURE;
494493
}
495494

0 commit comments

Comments
 (0)