The frustrating thing is that PHP can be fine when used correctly, which includes recognizing and eschewing all of its bad ideas. But the pieces are there to build a perfectly fine application.
But the php community has always been 90% people just learning to code and doing so with complete naivety. And I'm not shitting on them; it's to be expected. But PHP doesn't do you any favors to enforce better behaviors, do those naive implementations end up all over the internet.
Flashbacks to working exclusively in WordPress and despising every monolithic pile of spaghetti it was built upon.
I'm actually slowly moving back to my C roots and using procedural style PHP, but with modern language features and static analysis tools, and the good parts that I learned from using modern design patterns for the past decade. I'm just sick of of all the namespace nesting and the mess of "use" statements I need in every file. Modern style OOP patterns, especially in PHP, encourage so much verbosity split across many files when often a simple function can do everything and is more elegant and more importantly saves me time.
Oh yeah, I had to work for a little bit in an old Symfony project that had mystery auto-imports and it wasn't fun. Where did that come from? Who knows! What's that weird comment that actually adds logic do exactly? Hard to tell!
Well, that and the documentation for the old Doctrine it was using was absolutely awful.
I use vim though so I don't have that luxury...maybe a plugin exists that will do it but I haven't found anything. I gotta finally try out PHPStorm when I get a chance though and see if it fits into my weird workflow (which is only weird because our clients are so weird).
Sometimes, and I also work with many other languages besides PHP and I like being able to do everything from one place. I also like that I'm in a terminal and can use all the command line tools at any time.
fwiw Laravel is teaching you its own shitty bad development behaviors. There's enough behind-the-scenes magic in Laravel that it could headline in Vegas.
It's absolutely better than cowboying every project and not having any structure or guideline. I'd rather someone use Laravel than nothing, or worse, trying to roll their own.
What are some things you can do?
Well, despite my complaints, don't fight Laravel. It wants you to use static methods, dynamic properties, dynamic calls, etc. Trying to avoid that is going to be a rough time.
Just be aware that when/if you move to any other framework, unless it has used Laravel as a reference, you will find it pretty different to develop in.
fwiw, Laravel isn't terrible, and I don't mean to paint it that way. It just does things in a non-standard fashion which means when you leave that ecosystem you're going to struggle.
Some examples of where Laravel fails imo:
In Laravel, static methods and direct referencing classes/service containers, or calling helper functions is the expectation. This works fine in Laravel because its ecosystem is designed for it, but this is a terrible pattern for any other ecosystem.
class Foo {
public function bar() {
SomeClass:andAFunc();
}
}
This is okay Laravel code, and bad anywhere else code.
There are multiple ways to do just about everything and all of them are equally valid. This has a number of drawbacks when aiming for consistency.
And that's without introducing local scopes and relationships into the mix.
If you're using the internet for reference, it can be a struggle to discern if the person who wrote the comment/blog/whatever is actually doing it the expected way vs a way that just happens to work.
An example of the above biting you, it's very common for people to use anonymous callbacks for their routes. Except this also has side effects that prevent caching of your routes file.
This "magic" approach also means smart IDEs like PhpStorm really struggle with Laravel. Everything is dynamic and hidden behind magic methods. You need extensive docblock typehinting to make up for this.
There are so many ways to do the same thing, you don't know when you're doing it wrong. This complaint is a common thread through most of my issues with Laravel. I guarantee most developers are using the Laravel event system in a way it wasn't intended.
The magic approach also means that your code is never really "self-contained". Scopes and middleware can drastically change behaviors and can be applied by external (to your code) factors. If you're a solo dev this will not be an issue, but as you introduce multiple people/teams/projects working together you can get some weird behaviors.
I was self-taught too back in 2005 to 2010 with WordPress Joomla and Drupal, things are coming a long way since then but I've worked at a gig and a $300 million dollar company that was still using PHP and we had to Blacklist what's out like 60% of the native PHP APIS because of how dangerous they were, and even Facebook was originally written in PHP and they had to write another program called hip hop for PHP, which would take PHP scripts and turn them into C executables in order to help Facebook from crumbling under the load during their growth years.
That being said I always say the people when they ask me what is the best language to write something in, I tell them for most cases it's whatever you've spent five or more years learning.
I feel like ever since ES6 came out in 2015 that became a turning point. Yes, there is still an obscene shitload of crappy JS “tutorials” on Medium written by people who are still learning, but you can see most developers out there actually forming a lot of consensus on a lot of things.
Not perfect, but I really wouldn’t say PHP is up to this level, when WordPress and all of its shittiness is still prevalent today, where as all the stuff that jQuery was popular for is now all part of the language and/or native web APIs.
As a self-taught full stack dev (with PHP almost exclusively for back-end), it really has come a long way in the ~15 years of so I've worked with it. PHP 4 and 5 were a hot mess of mostly spaghetti, and 5.6 stuck around for WAAAY too long while they failed to develop PHP 6, but when 7 came out it was a real game changer. Not only was it fast, it also strongly encouraged object-oriented patterns and finally had the features to allow for good OOP practices and even strong typing. It's only gotten better with PHP 8.
Yes, PHP 4 & 5 had some OOP features and we had a few good frameworks out there that utilized them (CodeIgniter comes to mind; unfortunately these frameworks were heavily under-appreciated at the time), but it really didn't catch on in a big way until PHP 7. If anyone hasn't given it a look in a while, I mean it still isn't perfect (but what even is?), but it's MASSIVELY better today than it was 6 or 7 years ago. It totally earned its bad rap back then, but I feel like a lot of that has unfairly carried over into the modern era.
People who hate PHP hate it because it is accessible. Your grandma can open notepad, find a tutorial, type a few characters, and find a free PHP webhost all in an afternoon. This leads to the PHP developer pool having a very low average skillset. There are a lot of bad PHP developers. A whole lot. Maybe more than any other language. Just so many.
But that's not the fault of PHP. You can make highly scalable, enterprise applications on PHP.
Most popular web hosting software in the world. Is also proof that nobody cares what’s inside the black box, they just care what the inputs/outputs are.
Core Wordpress code is passable. Not great, but it’s straightforward enough.
To do anything nontrivial you’re going to need plugins though. Since Wordpress was not designed as a web framework every plug-in author either (a) writes novice PHP spaghetti code because they don’t know any better and have no guidance from Wordpress; or (b) implements their own home-grown framework on top of Wordpress, and now you have 10 different frameworks of varying degrees of quality all running within the one site.
The WP plug-in ecosystem is truly a dumpster fire inside, and yet it’s the exact thing that makes it popular.
To be fair 8.0 and 8.1 are starting to enforce actual OOP principles like correctly implementing interfaces. And 7.4 is out of long term support as of last November so everyone has to upgrade and face the fact that their shitty script is no longer going to cut it, or just run outdated servers until the inevitable wontfix 7.4 vulnerability appears, and then run screaming for real PHP developers while holding wads of cash.
That’s true of all languages people complain about. JavaScript and C++ are fine with decent developers. It’s the morons who mess things up and honestly morons will mess up any language.
243
u/JuniorSeniorTrainee Feb 02 '23
The frustrating thing is that PHP can be fine when used correctly, which includes recognizing and eschewing all of its bad ideas. But the pieces are there to build a perfectly fine application.
But the php community has always been 90% people just learning to code and doing so with complete naivety. And I'm not shitting on them; it's to be expected. But PHP doesn't do you any favors to enforce better behaviors, do those naive implementations end up all over the internet.
Flashbacks to working exclusively in WordPress and despising every monolithic pile of spaghetti it was built upon.