Edit report at https://bugs.php.net/bug.php?id=65111&edit=1

 ID:                 65111
 Updated by:         fel...@php.net
 Reported by:        ryan dot brothers at gmail dot com
 Summary:            Calling traits directly with static
                     properties/methods
-Status:             Open
+Status:             Assigned
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Linux
 PHP Version:        5.5.0
-Assigned To:        
+Assigned To:        gron
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2013-06-24 16:52:52] ryan dot brothers at gmail dot com

Description:
------------
The documentation for traits indicates that "it is not possible to instantiate 
a Trait on its own", but I have noticed that a trait can be called directly if 
it has a static property or method, as per the below example.  Is this intended 
behavior?  Or should traits be restricted from being called directly?  I was 
under the impression that traits cannot be called directly per the 
documentation.  If not, is there a way to prevent traits from being called 
directly as in the below example?

Test script:
---------------
<?php
trait t1
{
    public static $a1 = 'test1';

    public static function test()
    {
        return 'test2';
    }
}

echo t1::$a1."\n";
echo t1::test()."\n";


Expected result:
----------------
Fatal Error that traits cannot be called directly.

Actual result:
--------------
test1
test2



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65111&edit=1

Reply via email to