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.

Beautiful PHP

8 pointsby ooooakabout 12 years ago

8 comments

bradwestnessabout 12 years ago
Not exactly sure what the "tips" are in these, most of them just look like cruddy PHP code.<p>In the 2nd part of Example 2, using "else if" instead of several "if" statements to check the same value would result in fewer comparisons having to be done since the way it's written now the second comparison will always run even if the first one was true. It would be even better to use a switch statement if you're comparing the same variable in each case.
评论 #5310130 未加载
leeoniyaabout 12 years ago
posts like this make me wonder how the frontpage curating process works at HN (or doesnt). i've posted things that had more value and upvotes than whatever this is supposed to be and never made it to the front page. (also php-related, mind you)<p>my guess is that someone wants to show how dumb php programmers are by selectively promoting stuff like this. just sad.
jdiez17about 12 years ago
Hm, yeah, if a poorly written article with this "beautiful PHP" is what's needed to make it to the frontpage of "Hacker News" I think something has gone awfully wrong.<p>Not to mention most of the code is absolutely horrible and should not be used for anything.
sentientalabout 12 years ago
This seems representative of the PHP community in general. The only thing you need to qualify PHP as being "beautiful" is to apply a few tips on how to iterate over your array.<p>There are many other ways to make PHP beautiful. In fact, you can make object models that are almost as flexible, DRY and elegant as they would be in any other language.
SlyShyabout 12 years ago
Challenge to PHP programmers here: can you point me to some actual coding best practices for PHP (besides PHP the Right Way)?
评论 #5310120 未加载
评论 #5310598 未加载
sparkygoblueabout 12 years ago
Ugh. Articles like this make me want to join the PHP sucks crowd, and I really hate the PHP sucks crowd.
Gigablahabout 12 years ago
<p><pre><code> if ($string == '' || null) return 'massage'; </code></pre> Heh, beginner mistake.
评论 #5310079 未加载
benjubbabout 12 years ago
supposed to be ironic right?
评论 #5310036 未加载
评论 #5310073 未加载