|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75771 When using traits, class must be written prior to calling in same file.
Submitted: 2018-01-07 04:18 UTC Modified: -
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sybrew at gmail dot com Assigned:
Status: Open Package: Class/Object related
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: sybrew at gmail dot com
New email:
PHP Version: OS:


 [2018-01-07 04:18 UTC] sybrew at gmail dot com
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:

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";

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-07 04:52 UTC] spam2 at rhsoft dot net
without opcache that's even not bound to traits
 [2018-01-07 10:43 UTC] sybrew at gmail dot com
This issue is reproducible with Zend Opcache enabled.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Oct 06 17:05:51 2022 UTC