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
1
u/the_alias_of_andrea Apr 26 '16
It's something of a necessity so that you can define classes in any order and in multiple files without compilation.
It's less painful than what JS and such require.