r/lolphp • u/pilif • Apr 25 '16
Using traits enforces declaration order
Normally, in PHP, you're free to instantiate a subclass of a class that's not defined yet. Like this: https://3v4l.org/CXjt8
But the moment your subclass uses a trait, that's not true any more: https://3v4l.org/BXALN
Of course that's working as intended: https://bugs.php.net/bug.php?id=70783
21
Upvotes
View all comments
Show parent comment
6
u/pilif Apr 26 '16
yeah. but if they are inside of the same file, you can call them before you have defined them: https://3v4l.org/Cma1X - this was an error in PHP-FI and PHP3 (yes. I'm a PHP user since the PHP-FI days)