]> granicus.if.org Git - php/commitdiff
Convert "Only arrays and Traversables can be unpacked" into Error
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 27 Sep 2019 12:52:20 +0000 (14:52 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 27 Sep 2019 13:50:34 +0000 (15:50 +0200)
UPGRADING
Zend/tests/arg_unpack/invalid_type.phpt
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

index 28f1fbb477526b3205053dc577c7e44924a0e9bb..0a2b00db59a1dee983be20ef833e6ec6c7a07f5f 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -94,7 +94,8 @@ PHP 8.0 UPGRADE NOTES
       is already used.
     * Attempting to use an invalid type (array or object) as an array key or
       string offset.
-    * Attempting to write to an index of a scalar value.
+    * Attempting to write to an array index of a scalar value.
+    * Attempting to unpack a non-array/Traversable.
 
     RFC: Part of https://wiki.php.net/rfc/engine_warnings
 
index 1ef545558c7da54b7d868bd3598397d774315ca0..ad580c37ae9b0143ffcffdb447c5ae60080072ab 100644 (file)
@@ -7,53 +7,37 @@ function test(...$args) {
     var_dump($args);
 }
 
-test(...null);
-test(...42);
-test(...new stdClass);
-
-test(1, 2, 3, ..."foo", ...[4, 5]);
-test(1, 2, 3, ...new StdClass, ...3.14, ...[4, 5]);
-
-?>
---EXPECTF--
-Warning: Only arrays and Traversables can be unpacked in %s on line %d
-array(0) {
+try {
+    test(...null);
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
 }
-
-Warning: Only arrays and Traversables can be unpacked in %s on line %d
-array(0) {
+try {
+    test(...42);
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
 }
-
-Warning: Only arrays and Traversables can be unpacked in %s on line %d
-array(0) {
+try {
+    test(...new stdClass);
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
 }
 
-Warning: Only arrays and Traversables can be unpacked in %s on line %d
-array(5) {
-  [0]=>
-  int(1)
-  [1]=>
-  int(2)
-  [2]=>
-  int(3)
-  [3]=>
-  int(4)
-  [4]=>
-  int(5)
+try {
+    test(1, 2, 3, ..."foo", ...[4, 5]);
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
 }
-
-Warning: Only arrays and Traversables can be unpacked in %s on line %d
-
-Warning: Only arrays and Traversables can be unpacked in %s on line %d
-array(5) {
-  [0]=>
-  int(1)
-  [1]=>
-  int(2)
-  [2]=>
-  int(3)
-  [3]=>
-  int(4)
-  [4]=>
-  int(5)
+try {
+    test(1, 2, 3, ...new StdClass, ...3.14, ...[4, 5]);
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
 }
+
+?>
+--EXPECT--
+Only arrays and Traversables can be unpacked
+Only arrays and Traversables can be unpacked
+Only arrays and Traversables can be unpacked
+Only arrays and Traversables can be unpacked
+Only arrays and Traversables can be unpacked
index a146341b0cbfcfcc03caca2426c3181678668f83..7d9eab21f38a1c6c2e4068e7e89a3a4a7f58a445 100644 (file)
@@ -4969,7 +4969,7 @@ ZEND_VM_C_LABEL(send_again):
                zend_object_iterator *iter;
 
                if (!ce || !ce->get_iterator) {
-                       zend_error(E_WARNING, "Only arrays and Traversables can be unpacked");
+                       zend_type_error("Only arrays and Traversables can be unpacked");
                } else {
 
                        iter = ce->get_iterator(ce, args, 0);
@@ -5046,7 +5046,7 @@ ZEND_VM_C_LABEL(send_again):
                if (OP1_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(args) == IS_UNDEF)) {
                        ZVAL_UNDEFINED_OP1();
                }
-               zend_error(E_WARNING, "Only arrays and Traversables can be unpacked");
+               zend_type_error("Only arrays and Traversables can be unpacked");
        }
 
        FREE_OP1();
@@ -5752,7 +5752,7 @@ ZEND_VM_C_LABEL(add_unpack_again):
                zend_object_iterator *iter;
 
                if (!ce || !ce->get_iterator) {
-                       zend_throw_error(NULL, "Only arrays and Traversables can be unpacked");
+                       zend_type_error("Only arrays and Traversables can be unpacked");
                } else {
                        iter = ce->get_iterator(ce, op1, 0);
                        if (UNEXPECTED(!iter)) {
index d9c288c70766759d530c75923f4bb40b131e48f8..bf4eb31bfbfb103f0fcd4c629044e0184b863a5b 100644 (file)
@@ -1928,7 +1928,7 @@ send_again:
                zend_object_iterator *iter;
 
                if (!ce || !ce->get_iterator) {
-                       zend_error(E_WARNING, "Only arrays and Traversables can be unpacked");
+                       zend_type_error("Only arrays and Traversables can be unpacked");
                } else {
 
                        iter = ce->get_iterator(ce, args, 0);
@@ -2005,7 +2005,7 @@ send_again:
                if (opline->op1_type == IS_CV && UNEXPECTED(Z_TYPE_P(args) == IS_UNDEF)) {
                        ZVAL_UNDEFINED_OP1();
                }
-               zend_error(E_WARNING, "Only arrays and Traversables can be unpacked");
+               zend_type_error("Only arrays and Traversables can be unpacked");
        }
 
        FREE_OP(opline->op1_type, opline->op1.var);
@@ -2184,7 +2184,7 @@ add_unpack_again:
                zend_object_iterator *iter;
 
                if (!ce || !ce->get_iterator) {
-                       zend_throw_error(NULL, "Only arrays and Traversables can be unpacked");
+                       zend_type_error("Only arrays and Traversables can be unpacked");
                } else {
                        iter = ce->get_iterator(ce, op1, 0);
                        if (UNEXPECTED(!iter)) {