|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-10-25 13:11 UTC] joel at kociolek dot org
Description:
------------
I had perfectly working code. I added a trait to one of the classes and it started to produce fatal errors. I tried to cut down the complexity of the code and made the simplest example that I could do. See below.
Test script:
---------------
<?php
class B extends A {}
trait wtf {}
class A {
use wtf;
}
echo "OK\n";
Expected result:
----------------
Should display OK
Actual result:
--------------
Displays:
Fatal error: Class 'A' not found in /home/joel/php-5.6.14/test.php on line 2
Please note that removing the "use" line from the sample code above makes it work (It display "OK").
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 02:00:01 2025 UTC |
While classes can often be used before they are "defined" (in terms of where they are located in a file), this does not apply once you introduce traits. With traits, classes must be defined before they are used. Which is a good thing to do regardless. trait wtf {} class A { use wtf; } class B extends A {}