]> granicus.if.org Git - php/commitdiff
Fix assertion violation with composer
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 24 Jan 2017 10:32:04 +0000 (11:32 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 24 Jan 2017 10:32:41 +0000 (11:32 +0100)
Zend/tests/unused_shared_static_variables.phpt [new file with mode: 0644]
Zend/zend_opcode.c

diff --git a/Zend/tests/unused_shared_static_variables.phpt b/Zend/tests/unused_shared_static_variables.phpt
new file mode 100644 (file)
index 0000000..fc87a19
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Cleanup of shared static variables HT that has never been used should not assert
+--FILE--
+<?php
+
+class A {
+    public function test() {
+        static $x;
+    }
+}
+class B extends A {}
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
index 438feb4c9141d79b1c4353d43a4c5093ca154c33..7c797033383705b81bb80afcade19ed56c6b8a1d 100644 (file)
@@ -151,7 +151,14 @@ ZEND_API void zend_function_dtor(zval *zv)
 ZEND_API void zend_cleanup_op_array_data(zend_op_array *op_array)
 {
        if (op_array->static_variables &&
-           !(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) {
+           !(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)
+       ) {
+               /* The static variables are initially shared when inheriting methods and will
+                * be separated on first use. If they are never used, they stay shared. Cleaning
+                * a shared static variables table is safe, as the intention is to clean all
+                * such tables. */
+               HT_ALLOW_COW_VIOLATION(op_array->static_variables);
+
                zend_hash_clean(op_array->static_variables);
        }
 }