com php-src: Fix inference warning about missing key type: ext/opcache/Optimizer/zend_inference.c ext/opcache/tests/ invalid_array_key_type.phpt
| From: | Nikita Popov | Date: | Fri, 22 Feb 2019 10:55:16 +0000 |
| Subject: | com php-src: Fix inference warning about missing key type: ext/opcache/Optimizer/zend_inference.c ext/opcache/tests/ invalid_array_key_type.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104835@lists.php.net to get a copy of this message | ||
Commit: 2cfb09caa775a7b5851f2ee10fac3c870344a181
Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 22 Feb 2019 11:55:16 +0100
Parents: 538814385569525443c96e131d346a8fd7b6cbe3
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2cfb09caa775a7b5851f2ee10fac3c870344a181
Log:
Fix inference warning about missing key type
Changed paths:
M ext/opcache/Optimizer/zend_inference.c
A ext/opcache/tests/invalid_array_key_type.phpt
Diff:
diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c
index 5848778..9e88e45 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 0000000..f2e65be
--- /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===