Advanced PHP Tips Revisited
smashingmagazine.com
smashingmagazine.com
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.
Disclaimer: PHP is how I stay living indoors.
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."
a ? b ? c ? d : e : f ? g : h : i
Or something like that. That's not funny.