From: ryan dot brothers at gmail dot com Operating system: Linux PHP version: 5.5.0 Package: Class/Object related Bug Type: Bug Bug description:Calling traits directly with static properties/methods
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 bug report at https://bugs.php.net/bug.php?id=65111&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65111&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65111&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65111&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65111&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65111&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65111&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65111&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65111&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65111&r=support Expected behavior: https://bugs.php.net/fix.php?id=65111&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65111&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65111&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65111&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65111&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65111&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65111&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65111&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65111&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65111&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65111&r=mysqlcfg