Hacker News new | ask | show | jobs
by prplhaz4 2931 days ago
http://www.phptherightway.com/ attempts to do just that - can't vouch for its effectiveness, but is a resource that was at least updated for PHP 7...

https://github.com/codeguy/php-the-right-way

1 comments

I always hated the DI fervor in PHP, like it solves all problems. You get such gems from phptherightway as

> We can demonstrate the concept with a simple, yet naive example.

> Here we have a Database class that requires an adapter to speak to the database.

It tries so hard to be java, which seems backward.

If you remember that so, so much old PHP was reliant on global scope included from other files, it explains a lot of the DI obsession. If you were lucky, it was just a single bootstrap.php, but often not.
Just like when demonstrating object oriented programming with trivial examples, DI suffers the same problem. DI, or Inversion of Control (the thing you want to achieve "through" DI), works best at scale, not with Hello World examples. When you work on a large code base with a large team you need some philosophy and principles to guide you. Decoupling is one of those things. Since Java is often used to build large software projects you will see these techniques being used and we therefore associate these things with Java (i.e. the Java bloat). Over the past few years it seems that PHP has become an "easier" Java and it's therefore only natural that these techniques and approaches are then also applied.
I can only agree. I wrote a CMS with Zend Framework 2 which is heavy on DI and tries to be like Spring + Hibernate (Doctrine). Apart from being very hard to understand for new devs in the project, it's also very, very slow.

The way PHP is evolving is definitely towards the Java world and I think it's the worst decision they could make.

Moved to Go 5 years ago, never looking back.

Haven't had to use Zend but at least Symfony DI is really heavy to use with all the services.yamls and the javaisms it introduces.

DI can be heavy or it can be something mostly automagical like in Laravel. That's something I've enjoyed quite a bit. Basically it doesn't that much exist until you start needing special cases.

Quite a big part of the PHP community is gravitating towards Laravel and the new steam it introduced with OOB best practices and "let's try hard to avoid the Java-heaviness". Laravel seems to have quite nice balance between easy for new devs and bunch of powerful concepts when needed. Lots of basic problems solved OOB as well.

What is DI?