|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-06-24 17:09 UTC] felipe@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: gron
[2013-06-25 04:30 UTC] laruence@php.net
[2013-06-25 07:19 UTC] gron@php.net
[2013-06-25 15:15 UTC] felipe@php.net
-Status: Assigned
+Status: Not a bug
-Assigned To: gron
+Assigned To:
[2013-06-25 15:15 UTC] felipe@php.net
[2013-06-29 18:53 UTC] ryan dot brothers at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 15:00:01 2025 UTC |
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