johannes                                 Sat, 29 May 2010 20:01:08 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=299936

Log:
- A method called like a trait is no constructor

Changed paths:
    A   php/php-src/trunk/Zend/tests/traits/noctor001.phpt
    U   php/php-src/trunk/Zend/zend_compile.c

Added: php/php-src/trunk/Zend/tests/traits/noctor001.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/noctor001.phpt                          
(rev 0)
+++ php/php-src/trunk/Zend/tests/traits/noctor001.phpt  2010-05-29 20:01:08 UTC 
(rev 299936)
@@ -0,0 +1,28 @@
+--TEST--
+Don't mark trait methods as constructor
+--FILE--
+<?php
+trait Foo {
+    public function Foo() {
+    }
+}
+
+class Bar {
+    use Foo;
+    public function Bar() {
+    }
+}
+
+$rfoofoo = new ReflectionMethod('Foo::Foo');
+var_dump($rfoofoo->isConstructor());
+
+$rbarfoo = new ReflectionMethod('Bar::Foo');
+var_dump($rbarfoo->isConstructor());
+
+$rbarbar = new ReflectionMethod('Bar::Bar');
+var_dump($rbarbar->isConstructor());
+?>
+--EXPECT--
+bool(false)
+bool(false)
+bool(true)


Property changes on: php/php-src/trunk/Zend/tests/traits/noctor001.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c       2010-05-29 18:36:51 UTC (rev 
299935)
+++ php/php-src/trunk/Zend/zend_compile.c       2010-05-29 20:01:08 UTC (rev 
299936)
@@ -1591,7 +1591,7 @@
                        zend_str_tolower_copy(class_lcname, 
CG(active_class_entry)->name, CG(active_class_entry)->name_length);
                        /* Improve after RC: cache the lowercase class name */

-                       if ((CG(active_class_entry)->name_length == name_len) 
&& (!memcmp(class_lcname, lcname, name_len))) {
+                       if ((CG(active_class_entry)->name_length == name_len) 
&& ((CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != ZEND_ACC_TRAIT) && 
(!memcmp(class_lcname, lcname, name_len))) {
                                if (CG(active_class_entry)->constructor) {
                                        zend_error(E_STRICT, "Redefining 
already defined constructor for class %s", CG(active_class_entry)->name);
                                } else {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to