]> granicus.if.org Git - php/commitdiff
Handle resource keys in constexpr arrays
authorNikita Popov <nikic@php.net>
Wed, 28 Sep 2016 21:11:02 +0000 (23:11 +0200)
committerNikita Popov <nikic@php.net>
Wed, 28 Sep 2016 21:11:02 +0000 (23:11 +0200)
Zend/tests/const_array_with_resource_key.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/const_array_with_resource_key.phpt b/Zend/tests/const_array_with_resource_key.phpt
new file mode 100644 (file)
index 0000000..2533b78
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Constexpr arrays should be able to handle resource keys
+--FILE--
+<?php
+
+const FOO = [STDIN => 42];
+var_dump(FOO);
+
+?>
+--EXPECTF--
+Strict Standards: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
+array(1) {
+  [%d]=>
+  int(42)
+}
index d3bec3714e815282f886b5ce616a5a6d6b16c7a5..f91f029e486f04b9084693b6ea53c3d29c84b466 100644 (file)
@@ -5940,6 +5940,9 @@ void zend_do_add_static_array_element(zval *result, zval *offset, zval *expr) /*
                        case IS_NULL:
                                zend_symtable_update(Z_ARRVAL_P(result), "", 1, &expr, sizeof(zval *), NULL);
                                break;
+                       case IS_RESOURCE:
+                               zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(offset), Z_LVAL_P(offset));
+                               /* break missing intentionally */
                        case IS_LONG:
                        case IS_BOOL:
                                zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(offset), &expr, sizeof(zval *), NULL);