]> granicus.if.org Git - php/commitdiff
Fix inference warning about missing key type
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Feb 2019 10:55:16 +0000 (11:55 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Feb 2019 10:55:16 +0000 (11:55 +0100)
ext/opcache/Optimizer/zend_inference.c
ext/opcache/tests/invalid_array_key_type.phpt [new file with mode: 0644]

index 58487786169f0a42a213321781eaeebca1cc14bd..9e88e4566b1efc163c3bfbea2258fcbeb2e6146e 100644 (file)
@@ -2093,7 +2093,6 @@ static uint32_t assign_dim_result_type(
                tmp |= MAY_BE_RC1 | MAY_BE_RCN;
        }
        if (tmp & MAY_BE_ARRAY) {
-               tmp |= (value_type & MAY_BE_ANY) << MAY_BE_ARRAY_SHIFT;
                if (value_type & MAY_BE_UNDEF) {
                        tmp |= MAY_BE_ARRAY_OF_NULL;
                }
@@ -2114,6 +2113,11 @@ static uint32_t assign_dim_result_type(
                                tmp |= MAY_BE_ARRAY_KEY_STRING;
                        }
                }
+               /* Only add value type if we have a key type. It might be that the key type is illegal
+                * for arrays. */
+               if (tmp & MAY_BE_ARRAY_KEY_ANY) {
+                       tmp |= (value_type & MAY_BE_ANY) << MAY_BE_ARRAY_SHIFT;
+               }
        }
        return tmp;
 }
diff --git a/ext/opcache/tests/invalid_array_key_type.phpt b/ext/opcache/tests/invalid_array_key_type.phpt
new file mode 100644 (file)
index 0000000..f2e65be
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Don't add array value type is key type is illegal
+--FILE--
+<?php
+
+function test(\SplObjectStorage $definitions = null) {
+    $argument = new stdClass;
+    $definitions[$argument] = 1;
+    $definitions[$argument] += 1;
+    $argument = [];
+    $definitions[$argument] = 1;
+    $definitions[$argument] += 1;
+}
+
+?>
+===DONE===
+--EXPECT--
+===DONE===