News for hackers. Stuff that matters.
Re:PHP 5.5.8 Released by piokoch on Friday January 10, 2014 @03:05PM (#7039015)
PHP has a reputation as a language that makes dead easy to write very ugly sphagetti code. As far as I learned a lot has chaned since last time I was using PHP - something like 5 years ago.

Is there any good book or other resource which describes modern PHP with best practices, parts to avoid, etc?

Re:PHP 5.5.8 Released by paraxisi on Friday January 10, 2014 @03:09PM (#7039047)
I've seen this around a few times, seems to be what you're looking for http://www.phptherightway.com
Re:PHP 5.5.8 Released by mkramlich on Friday January 10, 2014 @04:37PM (#7039646)
In my judgement, PHP best practice is #1 to never write anything new in it. And where it does already exist, #2 is to ideally write replacements (or do an incremental migration) in something else with a better overall balance of positive to negatives, that fits best, typically Python, Java, C or a sh.
Re:PHP 5.5.8 Released by jtreminio on Friday January 10, 2014 @08:11PM (#7040921)
Your judgement kind of sucks.
Re:PHP 5.5.8 Released by janson0 on Friday January 10, 2014 @05:32PM (#7040079)
If I were you, and I wanted to see how elegant and great PHP can be, I would just go check out and learn Laravel 4.

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/

Re:PHP 5.5.8 Released by xemoka on Friday January 10, 2014 @05:47PM (#7040180)
And if you're going the Laravel route (which I certainly recommend, I've used it a couple times here and there when PHP has been required), check out CodeBright by Dayle Rees (a Laravel core team member) on Leanpub (https://leanpub.com/codebright). It was the manual I needed to get going.
Re:PHP 5.5.8 Released by sigzero on Friday January 10, 2014 @08:25PM (#7040988)
My\Full\Classname

Namespace convention sucks. That is all.

Re:PHP 5.5.8 Released by gedrap on Friday January 10, 2014 @04:27PM (#7039559)
>> PHP has a reputation as a language that makes dead easy to write very ugly sphagetti code.

I believe that programmers ability to write poor code is quite language agnostic.

Re:PHP 5.5.8 Released by wwweston on Friday January 10, 2014 @05:30PM (#7040059)
I'd agree that PHP really isn't that bad (at least, from the perspective of someone who started writing web apps using C, Perl, and Java). Some missing or clunky meta/higher level features feel limiting to me, but more or less it seems to be as successful as its other dynamic scripting siblings when it comes to tools devs have used to ship.

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).

Re:PHP 5.5.8 Released by gedrap on Friday January 10, 2014 @07:50PM (#7040830)
I totally agree with you, it's not a perfect language. However, given the nature of 9/10 web applications (CRUD with some relationships between models), it does it's job just fine.
Re:PHP 5.5.8 Released by gizmogwai on Friday January 10, 2014 @05:26PM (#7040026)
From my personal experience, I disagree. I have seen a greater percentage of poor codes in languages that a lower entry barrier than those that require more initial investment. Most poor coders I've met are lazy coders (in the wrong side of it).
Re:PHP 5.5.8 Released by gedrap on Friday January 10, 2014 @07:46PM (#7040808)
Yes, there are plenty of crap coders and agree with your argument but, again, it's not really the language's problem. Actually, I believe it's quite opposite. It's a side effect of success.

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.

Re:PHP 5.5.8 Released by umsm on Friday January 10, 2014 @05:59PM (#7040239)
Learn how to use the Symfony Framework:

http://symfony.com/

That is modern PHP done right.

Re:PHP 5.5.8 Released by dscrd on Saturday January 11, 2014 @06:43AM (#7042357)
Actually, Symfony seems like some kids went to basic OO design courses and took everything there seriously. It also causes the end product to be measurably the slowest in the world. http://www.techempower.com/benchmarks/

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.

Re:PHP 5.5.8 Released by asciimo on Friday January 10, 2014 @08:32PM (#7041015)
I'm not sure that PHP done like Java is "right."
Re:PHP 5.5.8 Released by krapp on Friday January 10, 2014 @08:51PM (#7041067)
I think the best answer, probably, is that modern PHP done right uses some kind of framework, or at least a PSR-0 autoloader, url routing, proper data security and some kind of templating to separate the logic from the view.

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.

Re:PHP 5.5.8 Released by jbeja on Friday January 10, 2014 @03:12PM (#7039063)
I am reading "Apress Expert PHP and MySQL", the code is very releasable, it teach good practices about security and sql management, is more target to beginners and intermediate level programmers, but i really like how the author view and teaching skills.
Re:PHP 5.5.8 Released by mikelbring on Friday January 10, 2014 @08:25PM (#7040984)
The Laravel book by Taylor (creator of Laravel) is great for even non-Laravel users. https://leanpub.com/laravel
Re:PHP 5.5.8 Released by fleitz on Friday January 10, 2014 @03:07PM (#7039033)
I'd recommend this for modern PHP: http://www.nodebeginner.org/

It's a great intro on how to write sphagetti code with out losing face.

Re:PHP 5.5.8 Released by jbeja on Friday January 10, 2014 @03:14PM (#7039077)
This is not a PHP book, and is pretty old to begin with.
Re:PHP 5.5.8 Released by aurora72 on Friday January 10, 2014 @03:12PM (#7039061)
Are you sure it's a PHP book? It says it's a node.js book.
Re:PHP 5.5.8 Released by vijayr on Friday January 10, 2014 @03:32PM (#7039170)
I think he is being sarcastic
Re:PHP 5.5.8 Released by macinjosh on Friday January 10, 2014 @03:14PM (#7039078)
smart ass