]> granicus.if.org Git - php/commitdiff
Fix bug #70106 (Inheritance by anonymous class)
authorBob Weinand <bobwei9@hotmail.com>
Tue, 21 Jul 2015 18:34:06 +0000 (20:34 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Tue, 21 Jul 2015 18:34:06 +0000 (20:34 +0200)
NEWS
Zend/tests/anon/011.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/NEWS b/NEWS
index 620046a5bdb149328aca0355990f9c17b00b5e91..908d8d9aa03e9a00bd5372f0443f608187b3ed0c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 06 Aug 2015, PHP 7.0.0 Beta 3
-
+- Core:
+  . Fixed bug #70106 (Inheritance by anonymous class). (Bob)
 
 23 Jul 2015, PHP 7.0.0 Beta 2
 
diff --git a/Zend/tests/anon/011.phpt b/Zend/tests/anon/011.phpt
new file mode 100644 (file)
index 0000000..0d16c87
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Ensure proper inheritance with get_class(anon class instance) used via class_alias (see also bug #70106)
+--FILE--
+<?php
+
+class_alias(get_class(new class { protected $foo = 1; }), "AnonBase");
+var_dump((new class extends AnonBase {
+       function getFoo() {
+               return $this->foo;
+       }
+})->getFoo());
+?>
+--EXPECT--
+int(1)
index 73bb387c1eab391ed37208eedc5ced81dd4867dd..ce4365896cca1bd4227569cd3d2d0ae194594d31 100644 (file)
@@ -5172,11 +5172,11 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */
                }
 
                name = zend_new_interned_string(name);
-               lcname = zend_new_interned_string(lcname);
        } else {
                name = zend_generate_anon_class_name(decl->lex_pos);
-               lcname = zend_string_copy(name); /* this normally is an interned string, except with opcache. We need a proper copy here or opcache will fail with use after free. */
+               lcname = zend_string_tolower(name);
        }
+       lcname = zend_new_interned_string(lcname);
 
        ce->type = ZEND_USER_CLASS;
        ce->name = name;