summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-02-22 11:55:16 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-02-22 11:55:16 +0100
commit2cfb09caa775a7b5851f2ee10fac3c870344a181 (patch)
treefe30ba51e0f0faa882c264554985527dace10217
parent538814385569525443c96e131d346a8fd7b6cbe3 (diff)
downloadphp-git-2cfb09caa775a7b5851f2ee10fac3c870344a181.tar.gz
Fix inference warning about missing key type
-rw-r--r--ext/opcache/Optimizer/zend_inference.c6
-rw-r--r--ext/opcache/tests/invalid_array_key_type.phpt18
2 files changed, 23 insertions, 1 deletions
diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c
index 5848778616..9e88e4566b 100644
--- a/ext/opcache/Optimizer/zend_inference.c
+++ b/ext/opcache/Optimizer/zend_inference.c
@@ -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
index 0000000000..f2e65bedba
--- /dev/null
+++ b/ext/opcache/tests/invalid_array_key_type.phpt
@@ -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===