Live data from Hacker News

PHP: The Right Way

phptherightway.com

21–30 of 233 posts

Re: PHP: The Right Way

#21
post #11
post #9

I'm wondering why a specific code style is 'enforced' while it has nothing to do with interoperability. 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.

I think it's less about being "superior" than standardizing on a common style. Makes it easier to get up and running with someone else's code. But if your team agrees on a common but different style, that's fine too. It accomplishes the same goal. I'm only suggesting the official standard for new PHP developers.

Right. I think the main take-away from it is to be consistent and make sure everyone on your team is on the same page about the coding style. I see the PSR as a basic set of good recommendations, rather than something that must be followed. It's a good idea to follow it, but at least follow something.

My only complaint with it personally is that I Can. Not. Stand. putting opening brackets on their own line.

Re: PHP: The Right Way

#22
post #9

I'm wondering why a specific code style is 'enforced' while it has nothing to do with interoperability. 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.

PSRs where decided based on the most common standards used by some of the biggest PHP projects around. It wasn't a single person setting a standard. PSRs are completely optional.

However, you miss the point. The point of this isn't really to define all the options. Rather, it's to spell out best practices (and PSR-0 is really a best practice, and all about interoperability) that the community generally agrees with. Better to have a standard coding style than to have none at all, and if you have to choose one, PSR-1 and 2 are an excellent choice (considering how it was devised).

Re: PHP: The Right Way

#24

One point in and its already dead wrong, you never filter input, only output. Edit: Everyone talking about databases: paramaterized queries, check them out.

SQL injection attacks alone are almost always a result of not filtering input...

Re: PHP: The Right Way

#25
post #23

I suggest that you open up the doc source on github so that you can attract contributions from people while still maintaining editorial control. A good example is: python-guide.org -- http://docs.python-guide.org/en/latest/index.html

[deleted]

Re: PHP: The Right Way

#26
post #23

I suggest that you open up the doc source on github so that you can attract contributions from people while still maintaining editorial control. A good example is: python-guide.org -- http://docs.python-guide.org/en/latest/index.html

As mentioned elsewhere in the comments, I'll be moving over to GitHub Pages tonight to do exactly this.

Re: PHP: The Right Way

#27
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 :)

Re: PHP: The Right Way

#28
post #27

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

I agree. It's very much in a v1.0 form right now. Once I move over to GitHub Pages, I hope to add more links to tutorials and code samples without bloating the document itself.

Re: PHP: The Right Way

#29
post #23

I suggest that you open up the doc source on github so that you can attract contributions from people while still maintaining editorial control. A good example is: python-guide.org -- http://docs.python-guide.org/en/latest/index.html

There is a bit in the Introduction section of the doc that says how to contribute. Its actually just a one page on github at the moment that you can fork and send in pull request.

Re: PHP: The Right Way

#30
post #24

One point in and its already dead wrong, you never filter input, only output. Edit: Everyone talking about databases: paramaterized queries, check them out.

SQL injection attacks alone are almost always a result of not filtering input...

With parametrized queries, that becomes a non-issue, but I still see no point in cluttering the database with data that's just going to be filtered out at some point - might as well filter it before it goes into the DB to begin with. The exception, of course, being those rare cases when some users need to see the filtered data and others need to see the raw data, but even then, you likely won't want to allow everything.
Post reply on HN