Live data from Hacker News

PHP: The Right Way

phptherightway.com

71–80 of 233 posts

Re: PHP: The Right Way

#71
post #44

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. 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 com…

PSR-2 isn't trying to say that there is one correct answer. Instead they're trying to provide a single answer from the many valid possibilities.

"When various authors collaborate across multiple projects, it helps to have one set of guidelines to be used among all those projects"

Re: PHP: The Right Way

#72

I didn't understand this: 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().

Methods should be camelCase(), but properties (fields?) can be any convention as long as its consistent throughout.

Yup, that's my basic reading comprehension dropping out again. Thank you, that does make sense.

Re: PHP: The Right Way

#73

Really hope they fix the formatting. Unreadable for me, the font is way too big.

user: kaolinite 20 year old Python/PHP/C developer That font will be just perfect for you in about 15-20 years.

I'm 20 too and always read articles with 300%-500% zooming if there is no vertical scrollbar. Occassionally putting the glasses down and still be able to read is a huge relief!

Re: PHP: The Right Way

#74
post #17

Earlier quoted context omitted.

How is that a "bullshit PHP rule"? If you for loop in C, setting a pointer each iteration, you would expect the pointer to still be set the the last assignment in the loop once you're out of it.

C lets you define variables with block scope: int main(int argc, char *argv[]) { for(int i=0;i The last line fails to compile—'i' is no longer defined after exiting the loop. Java: public static void main(String[] args) { for(int i=0;i That also won't compile. Coming from a language that supports variables with block scope, PHP's behavior is very surprising indeed. If the first mention of $object is in the loop, I ca…

I was thinking more of:

  #include 
  int main()
  {
          int arr[10] = {1,2,3,4,5,6,7,8,9,0}, *ptr;

          for(int i = 10; i>=0; i--)
          {
                  ptr = &arr[i];
                  printf("%d\n", *ptr);
          }
          printf("%d\n", *ptr);
  }

Re: PHP: The Right Way

#75

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

Input is almost always filtered. Without mincing the semantics of that, let's say you receive free-form NL query as input. You don't filter that to reduce it to core terms you send to the database? You don't remove prepositions? You don't tokenize at all? Input is ambiguous and reduced/filtered into pseudo-meaningful terms to return relevant output.

If I want to tweet

  I 
you could pre-encode that as safe to paste into raw SQL, or as well-formed (X)HTML, but you can't do both simultaneously. Either encoding would end up distorting the content in the other context. You have to encode during output (and writing to a database counts) using the rules of the system consuming that output. Lots of crappy web forums visibly mangle punctuation in a futile effort to avoid this.

Re: PHP: The Right Way

#77

Earlier quoted context omitted.

The difference is the same as between http and https.

Not sure if you are trying to make a joke (and if so, it's incredibly subtle), or you are being serious. In case you are serious, to explain how HTTPS as it's used means anything about the trust-worthiness of the two parties involved?

Look at the original post. "curl -s http://getcomposer.org/installer | php" It's not just about trusting Composer, it's about trusting every point between you and their server. If I want to know that I am actually executing Composer I need to use a secure download method.

Re: PHP: The Right Way

#78
PHP with these guidelines looks like JAVA to me, but without the relatively sane foundations.

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!".

(The word-by-word translation is "your - root - messy - and/but - leaves/result - governed/orderly - have ? not - hey!")

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.

Edit: added word-by-word translation + typo fixes.

Re: PHP: The Right Way

#79
Right way to write PHP indeed. Sometimes I wish PHP itself was written this way.

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.

Not PHP specific, I admit.

Re: PHP: The Right Way

#80
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?
Post reply on HN