]> granicus.if.org Git - php/commitdiff
Convert SPL illegal offset type into TypeError
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 3 Aug 2020 09:16:59 +0000 (11:16 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 3 Aug 2020 09:17:49 +0000 (11:17 +0200)
Make this consistent with the corresponding engine behavior.
Also adjust the messages to match.

ext/spl/spl_array.c
ext/spl/tests/ArrayObject_illegal_offset.phpt [new file with mode: 0644]
ext/spl/tests/ArrayObject_illegal_offset_leak.phpt [deleted file]

index 69d79a7501a85eaee48dc9ac91a8083c6a6645d8..67539b1745ea1ff57e298ce7887d82ada4ba74a3 100644 (file)
@@ -375,7 +375,7 @@ num_index:
                ZVAL_DEREF(offset);
                goto try_again;
        default:
-               zend_error(E_WARNING, "Illegal offset type");
+               zend_type_error("Illegal offset type");
                return (type == BP_VAR_W || type == BP_VAR_RW) ?
                        &EG(error_zval) : &EG(uninitialized_zval);
        }
@@ -499,7 +499,7 @@ num_index:
                        ZVAL_DEREF(offset);
                        goto try_again;
                default:
-                       zend_error(E_WARNING, "Illegal offset type");
+                       zend_type_error("Illegal offset type");
                        zval_ptr_dtor(value);
                        return;
        }
@@ -585,7 +585,7 @@ num_index:
                ZVAL_DEREF(offset);
                goto try_again;
        default:
-               zend_error(E_WARNING, "Illegal offset type");
+               zend_type_error("Illegal offset type in unset");
                return;
        }
 } /* }}} */
@@ -661,7 +661,7 @@ num_index:
                                ZVAL_DEREF(offset);
                                goto try_again;
                        default:
-                               zend_error(E_WARNING, "Illegal offset type");
+                               zend_type_error("Illegal offset type in isset or empty");
                                return 0;
                }
 
diff --git a/ext/spl/tests/ArrayObject_illegal_offset.phpt b/ext/spl/tests/ArrayObject_illegal_offset.phpt
new file mode 100644 (file)
index 0000000..df25e4f
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+ArrayObject illegal offset
+--FILE--
+<?php
+
+$ao = new ArrayObject([1, 2, 3]);
+try {
+    var_dump($ao[[]]);
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
+try {
+    $ao[[]] = new stdClass;
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
+try {
+    $ref =& $ao[[]];
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
+try {
+    var_dump(isset($ao[[]]));
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
+try {
+    unset($ao[[]]);
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Illegal offset type
+Illegal offset type
+Illegal offset type
+Illegal offset type in isset or empty
+Illegal offset type in unset
diff --git a/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt b/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt
deleted file mode 100644 (file)
index 42c649d..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
---TEST--
-Assignments to illegal ArrayObject offsets shouldn't leak
---FILE--
-<?php
-
-$ao = new ArrayObject([1, 2, 3]);
-$ao[[]] = new stdClass;
-
-?>
---EXPECTF--
-Warning: Illegal offset type in %s on line %d