Is there any good book or other resource which describes modern PHP with best practices, parts to avoid, etc?
Is there any good book or other resource which describes modern PHP with best practices, parts to avoid, etc?
I recently moved from CodeIgniter 2.x over to Laravel, and it was like breathing fresh new air at the top of a mountain. Everything is cutting edge, organized, and fun to code again. Sounds like hyperbole, but for real it reinvigorated my programming efforts.
Check it out here: http://laravel.com/
Namespace convention sucks. That is all.
I believe that programmers ability to write poor code is quite language agnostic.
PHP was suitable for new programmers because of how easy it is to deploy, learn. PHP3, the first version of PHP which was widespread, was released during the dot com bubble. When everyone and their mums was into Web. Everyone started writing tutorials, passing their shitty skill set. to new developers. Which produced more crap developers.
The big problem with PHP is that it grew to popularity as it grew into a turing-complete templating language, and the major paradigm for it was more or less the idea that documents are programs. That actually encouraged mixture of logic and presentation concerns.
There are some other warts possibly worth railing at, but that's really the main place it gets its probably deserved reputation for having more spaghetti code, even though pros working in have long since moved on from that paradigm.
FWIW, this is also its strength: it's a very short distance with a gentle curve from authoring documents to authoring dynamic documents. I don't think anything else matches it.
Of course, the curve from there to a larger application, that can be a different story, depending on what kind of guidance one has (and most likely, without guidance, ontology will recapitulate philology, as they say).
That is modern PHP done right.
It can (and has been) argued that PHP is itself a templating language and that the added abstraction of something like Twig is unnecessary... while that's technically true, scaling that gets you trainwrecks like Wordpress' API, where it's all but impossible to write plugins without mixing html in with the code. You also get nice things like macros, auto-escaping, and caching with a template engine, and you would probably end up having to reimplement a lot of that at some point anyway.
Although what Laravel uses (blade) for templating looks pretty close to bare PHP, so there's plenty of room for minimal abstraction.
But all of it is light-years ahead of the nightmare that is typical legacy PHP.
I think this is the worst symptom: Sure, you can write snappy code that performs fast but when you try to reach a higher abstraction level, all those fundamental design failures catch up and make everything awkward and just bad.
It's a great intro on how to write sphagetti code with out losing face.