TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PHP: The Right Way

393 pointsby bencevansalmost 13 years ago

26 comments

rickmbalmost 13 years ago
Straight, simple and to the point. Nice.<p>Missing test and QA tools though. Probably an oversight, since the author does suggest following Derick Rethans and Sebastian Bergmann.<p>And another one: read up on the SPL library before you start re-inventing that wheel.
评论 #4212739 未加载
nikicalmost 13 years ago
I like the general idea of this, but think that it is nearly useless in its current form. It's way too superficial. To teach newbies how to do things right it doesn't suffice to link to a few resources and hope that they'll read them (hint: they won't). Instead one needs more concrete code examples, etc. Which would obviously be too much for one page :)
评论 #4214015 未加载
评论 #4212862 未加载
评论 #4213955 未加载
gbogalmost 13 years ago
PHP with these guidelines looks like JAVA to me, but without the relatively sane foundations.<p>It is fun how much a very old moralist sentence by Confucius applies well to PHP. He said 其本亂而末治者否矣 which can be translated, in software language development context, as "Build a nice, reliable language on shitty definition? Bullshit!".<p>(The word-by-word translation is "your - root - messy - and/but - leaves/result - governed/orderly - have ? not - hey!")<p>This sentence also resonates with the odd Turkish encoding PHPbug recently reported here: if you have so many wrong architecture decisions in the core of your product, no amount of patching and "under the rub" filling will save you.<p>Edit: added word-by-word translation + typo fixes.
评论 #4213638 未加载
评论 #4213319 未加载
评论 #4213223 未加载
aw3c2almost 13 years ago
<i></i><i>curl -s <a href="http://getcomposer.org/installer" rel="nofollow">http://getcomposer.org/installer</a> | php</i><i></i><p>is creepy. Never ever run other people's code without at least giving it a glance.
评论 #4212935 未加载
评论 #4212933 未加载
评论 #4214388 未加载
评论 #4212959 未加载
评论 #4220162 未加载
评论 #4213674 未加载
评论 #4212922 未加载
评论 #4213408 未加载
评论 #4212962 未加载
lukiferalmost 13 years ago
While PSR-1 has pretty good universal guidelines, PSR-2 goes too far in insisting on subjective preferences (spaces over tabs, 80-char lines, bracketing styles). We should not pretend that there is a "correct" answer to these choices, just as long as they stay consistent on a per-project basis.<p>All told, I love site, and I hope it keeps iterating. PHP may be ugly, but it's powerful, and most of its bad reputation comes from good coders having to pick up the pieces from bad coders.
评论 #4213083 未加载
评论 #4213032 未加载
jimmytucsonalmost 13 years ago
I didn't understand this:<p><pre><code> 4.2. Properties This guide intentionally avoids any recommendation regarding the use of $StudlyCaps, $camelCase, or $under_score property names. Whatever naming convention is used SHOULD be applied consistently within a reasonable scope. That scope may be vendor-level, package-level, class-level, or method-level. 4.3. Methods Method names MUST be declared in camelCase().</code></pre>
评论 #4213048 未加载
评论 #4213060 未加载
评论 #4213045 未加载
TylerEalmost 13 years ago
Something to consider mentioning - there are some in PHP these days that take this sort of stuff a bit too far. Drives me nuts to see people writing classes to encapsulate a 3 column database result. So much overhead and boilerplate.
评论 #4212771 未加载
评论 #4212901 未加载
postfuturistalmost 13 years ago
As a part-time PHP hater who often has to work with it professionally, I believe this is a fantastic resource. The bit on databases in particular is something that all PHP devs should read.<p>That said, it is difficult to bring a legacy code base in line with modern style, though you can improve it over time.<p>Also, this could benefit from some other gotchas, extremely surprising behavior and best practices for avoiding common pitfalls.
评论 #4214607 未加载
kingkilralmost 13 years ago
One point in and its already dead wrong, you never filter input, only output.<p>Edit: Everyone talking about databases: paramaterized queries, check them out.
评论 #4212939 未加载
评论 #4212800 未加载
评论 #4212909 未加载
评论 #4212979 未加载
评论 #4213650 未加载
评论 #4212832 未加载
_ikke_almost 13 years ago
I'm wondering why a specific code style is 'enforced' while it has nothing to do with interoperability.<p>Libraries with different code styles can be used together without problems. It seems like they are using the PSR to declare they're own style as superior.
评论 #4212818 未加载
评论 #4212765 未加载
评论 #4213239 未加载
stephenhandleyalmost 13 years ago
<a href="http://jeena.net/images/2012/PHP-The-Good-Parts.pdf" rel="nofollow">http://jeena.net/images/2012/PHP-The-Good-Parts.pdf</a>
评论 #4214903 未加载
gabordemooijalmost 13 years ago
I dont agree with the article all the way but it's certainly refreshing to see people trying to improve PHP coding practices instead of just complaining. Very well done.<p>That being said... Every language has its strengths and weaknesses. There is nothing fundamentally wrong with PHP (except maybe that if you look at it it's not a very exciting language, even a bit boring). Security for instance has nothing to do with the language itself. And as for PHP syntax, it's a blessing compared to some other languages; at least we don't have a semicolon debate in PHP land ;-)
etanolalmost 13 years ago
The comments about namespace are somehow ironic: is it very common to find developers that know what classes are but not namespaces? The namespace concept is much simpler than class. Which makes me wonder: who is the target audience?
评论 #4213178 未加载
评论 #4213397 未加载
评论 #4213738 未加载
xdalmost 13 years ago
Hey, nice work. Wouldn't a wiki platform work better however, instead of git?<p>Edit: also might be worth adding a bit about steering clear of phpclasses.org as well as w3schools, they bother contain far more bad, than good code.
评论 #4212776 未加载
评论 #4212796 未加载
socraticalmost 13 years ago
Are there any good books (or other resources) on modern PHP?<p>I last used PHP back with PHP3 (and then went C++ =&#62; Java =&#62; Python =&#62; Python/JavaScript =&#62; Ruby =&#62; Python/R), but a bunch of code I want to read at work uses PHP (with Zend). I no longer remember most of what I learned about PHP3, though obviously the PHP syntax seems to be at least somewhat readable as a sort of amalgam of Perl and C++ syntax and idioms. What does, e.g., Facebook use to get engineers who don't know PHP (but might know C++ or Python) up and running?
评论 #4213231 未加载
评论 #4213378 未加载
btbytesalmost 13 years ago
I suggest that you open up the doc source on github so that you can attract contributions from people while still maintaining editorial control.<p>A good example is: python-guide.org -- <a href="http://docs.python-guide.org/en/latest/index.html" rel="nofollow">http://docs.python-guide.org/en/latest/index.html</a>
评论 #4212844 未加载
评论 #4212866 未加载
评论 #4212833 未加载
aichialmost 13 years ago
Why the hell is required space indentation instead of tabs? Don't you know how to setup your editor? Don't you know that there are coders with special needs and they would like to setup another indentation, because they are using e.g. font size 20px to see your code?
countessaalmost 13 years ago
this is great stuff - I'm a casual php hacker and this is just the sort of thing I need to help me out when I'm working in the language - saves me from having to be deeply embedded in the culture of a language I don't use "all day every day"....so thanks!
pjmlpalmost 13 years ago
This is a very nice guide for everyone that has to work with PHP.
lekealmost 13 years ago
Nice read. TIL I should be doing some things differently in PHP.
kaolinitealmost 13 years ago
Really hope they fix the formatting. Unreadable for me, the font is way too big.
评论 #4213010 未加载
评论 #4213037 未加载
sneakalmost 13 years ago
PHP: Not even once.
ObnoxiousJulalmost 13 years ago
Right way to write PHP indeed. Sometimes I wish PHP itself was written this way.<p>Oh! The guide does not mention the case: if a class contains only one static method, please, use a function. It does not look as educated, but it's obviously a function.<p>Not PHP specific, I admit.
评论 #4213392 未加载
评论 #4213362 未加载
评论 #4213349 未加载
wseymouralmost 13 years ago
I think that Lithium (www.lithify.me) would be really great to mention under the 'popular frameworks' section.
评论 #4212729 未加载
erikbalmost 13 years ago
I like it. Would be smart to add some kind of picture for sharing Facebook is more successful if people not just see text.
评论 #4215726 未加载
BadCRCalmost 13 years ago
These guidelines won't save you from some bullshit PHP "rules", such as: <a href="http://stackoverflow.com/questions/5810168/php-foreach-by-reference-causes-weird-glitch-when-going-through-array-of-objects" rel="nofollow">http://stackoverflow.com/questions/5810168/php-foreach-by-re...</a>
评论 #4212789 未加载
评论 #4213656 未加载
评论 #4212903 未加载