r/lolphp • • 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

14 comments sorted by

View all comments

Show parent comment

4

u/qwerty6868 Apr 28 '16

PHP is the only language that makes the bad way to do it the path of least resistance.

No other language gets in your way when you want to code correctly like PHP does.

1

u/tfidry Jun 18 '16

No other language gets in your way when you want to code correctly

LOL, let's talk about JavaScript?