9 comments

[ 3.1 ms ] story [ 37.2 ms ] thread
Short summary:

1. Validate/clean input. Preferably store data in 3 arrays to ensure separation of input, cleaned data and cleaned data to be used with sql. Or cleaned data to be used with prepared sql-statements. Uhm yes.

2. The PHP type-system is retarded and can return integers treated as boolean false. Compare against !== FALSE when 0 is a valid return value from whatever function you just called, instead of simply checking the return value.

3a. The PHP runtime is retarded and wont choke if you refer to unexisting or unitialized variables. Initialize variables.

3b. Shortcuts which saves you a few keystrokes can result in poor maintainability. Use braces.

3c. Write readable (not "smart") code.

4a. Shortcuts which saves you a few keystrokes can result in poor maintainability. Use braces.

4b. Be consistent.

5. Use simple replace-functions when you don't need full regexp.

6. The ternary-operator is advanced & confusing. We recommend against using it.

7. Caching might improve performance.

8. Frameworks exists. You may or may not use them.

9. Writing buggy code that causes errors is silly and costs resources. Try not writing buggy code that needs to eat errors runtime.

10. Strlen is slow. Use isset on strings as arrays to check for specific lengths. Nevermind compromising rule 3c and in doing so also compromising rule 4b.

Call me picky, but I wont go as far as calling this advanced.

Yep, this is why PHP gets a bad rap in a lot of cases. I keep seeing lots of posts about "N PHP Components". Downloading/reading the code of those components makes it blatantly obvious that it was some designer who wrote them and not someone intimate with the language.

Disclaimer: PHP is how I stay living indoors.

However sad it might be, this probably is advanced for most PHP devs. Just take a look at the original article to see where I'm coming from. :)
Most PHP devs I've worked with (myself included) would consider these tips so trivial as to be expected knowledge. So don't be so unfair on PHP developers--the good ones find the ridiculous questions on PHP.net, and articles like this, just as stupid as you apparently do.
I'm a long was from being unfair. I think given the site this article is posted on my statement shouldn't have been hard to follow the context. There is a lot, and I mean a lot of PHP code being written by designers and very inexperienced 'developers', this article is geared towards /hopefully/ correcting some of the common mistakes the original article was promoting. I also don't think it's unfair to say most PHP users fall into this category.
I remember pulling my hair out over PHP's type-system. The boolean comparisons early on were strange to me.

Explode is really useful for string manipulation, for some reason I had issues with certain ways of doing split.

As for frameworks, I know the two big ones are Code Igniter and CakePHP, but the discussions I've seen have boiled down to documentation, which Code Igniter really does well. I've used Code Igniter and only have a few complaints, but overall, it's not bad. It's hard to compare with Ruby on Rails, but overall, PHP is a fairly quick and dirty solution and it "just works."

Ternary is advanced and confusing? It's neither of those things.
It is when you use nested ternary operators and are too lazy to write parentheses. I've seen code like

  a ? b ? c ? d : e : f ? g : h : i
Or something like that. That's not funny.
I wonder if the original intent of posting was to be helpful or for mockery. My second language to learn was PHP, perl being the first, and I have since moved on. I probably asked,( myself/google not others,) similar questions the article covers. But the fact that articles like this continue to be titled "Advanced..." is a hint to where the language and community are as a whole. I think the bigger issue is a commingling of subjects. If your intent is to learn PHP, learn programming with PHP as a language. If your intent is to learn web development, learn web development in terms of available technologies, industry standards, and best practices. A lot of the articles content is laughable not because it is common sense PHP, but common sense programming/web development. PHP != Web... or is that PHP !== Web?