Bug #75771 [Com]: When using traits, class must be written prior to calling in same file.

From: Date: Sun, 07 Jan 2018 04:52:49 +0000
Subject: Bug #75771 [Com]: When using traits, class must be written prior to calling in same file.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213401@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75771&edit=1 ID: 75771 Comment by: spam2 at rhsoft dot net Reported by: sybrew at gmail dot com Summary: When using traits, class must be written prior to calling in same file. Status: Open Type: Bug Package: Class/Object related Operating System: * PHP Version: Irrelevant Block user comment: N Private report: N New Comment: without opcache that's even not bound to traits see https://bugs.php.net/bug.php?id=75542 Previous Comments: ------------------------------------------------------------------------ [2018-01-07 04:18:10] sybrew at gmail dot com Description: ------------ When a class is called from the same file it's written, you should be able to call them in any order. However, when a class uses a trait, the order is strict. Test script: --------------- <?php new A; // good. new B; // fatal error. class A { function __construct() { echo 'constructed A', "<br>\n"; } } class B { use T; function __construct() { echo 'constructed B', "<br>\n"; $this->traitfunc(); } } new B; // good. trait T { function traitfunc() { echo 'traitfunc called', "<br>\n"; } } Expected result: ---------------- constructed A constructed B traitfunc called Actual result: -------------- constructed A FATAL ERROR Class 'B' not found on line number 4 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75771&edit=1

« previous php.bugs (#213401) next »