From:             phpbugs at catchall dot drarok dot com
Operating system: OS X 10.8
PHP version:      master-Git-2012-11-29 (Git)
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Trait method names matching classes that use said trait treated 
as constructors

Description:
------------
If you use a Trait which has a method name matching your class name, it is
used as 
an old-style constructor in the case where the using class doesn't define a

constructor.

If you *do* define a constructor, you receive the error "Fatal error: Hello
has 
colliding constructor definitions coming from traits".

Test script:
---------------
<?php
trait HelloWorld {
        public function hello() { echo 'Hello, World!', PHP_EOL; }
        static public function world() { echo 'World; Hello!', PHP_EOL; }
}

class Hello { use HelloWorld; }
class World { use HelloWorld; }

new Hello();
new World();

/*
 * # php example.php
 * Hello, World!
 * World; Hello!
 */

Expected result:
----------------
Given that Traits cannot be used in legacy code, I'd expect the method name
to be 
irrelevant to constructor behaviour.

Actual result:
--------------
Method names that match the class name are used as a constructor.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=63646&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63646&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63646&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63646&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63646&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63646&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63646&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63646&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63646&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63646&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63646&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63646&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63646&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63646&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63646&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63646&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63646&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63646&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63646&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63646&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63646&r=mysqlcfg

Reply via email to