Learning PHP – Things to Remember

As I continue on with Drupal I’m also beginning to digest PHP. I’ve worked with just about every programming language there is: Java, C, C++, Cold Fusion, Python, Perl, and even Fortran. I find scripting languages an excellent choice for web programming. However there is always a few tricks that you need to know – and these are easy to forget. I’m going to use this post as a place to “remember” these. Once I get enough I’m going to turn this into a page. If you have any tricks you’d like to contribute, just post a comment.

Things To Remember with PHP 5:

  • Use isset() to test if a variable has a value.
  • variable names are case sensitive; functions and stuff are not
  • PHP is cool; Perl is not {just checking to see if you are paying attention :-)}
  • When working with numbers watch out for wacky type conversion issues between types. Integers over about 2 billion are converted over to floats automatically. Booleans that are true convert to 1 but false converts to an empty string. Use type casting.
  • Variable variables are interesting (kind of like c pointers). As with c pointers, if you don’t know what you’re doing then do not use them.
  • Superglobal Arrays are incredibly useful, but also dangerous and a source of too much pasta in your programming diet.
  • Objects are always passed by reference.
  • Function arguments are pass by value with “$arg1” notation; to pass by reference use “&$arg1” notation.
  • Use PDO for database connectivity.
  • The foreach loop is powerful for iterating over arrays
  • There are a number of very powerful array functions that are especially suited to database applications.
  • Understand how things work before you use them not after – for example if you use XAMPP make sure you know the differences between their PHP config and the default from php.net because they are not the same.
  • The ending “%>” is not required anymore…
  • Control your extensions in php.ini and don’t have more than you really need.
  • Regular Expressions are a key to high performance PHP applications.

Finally – these are fantastic PHP links to use for learning:

I’ll update this as I continue to learn more about PHP. My main focus will be on developing database applications and looking at application architectures.

7 Responses

  1. Plutarch says:

    Some good tips here. Do you take requests?

    Would like to see a tutorial on PHP + WSO2!

  2. berenerchamion says:

    You read my mind! Now that I have a decent MySQL programming tool – see my latest entry – I’ll be cranking on a PHP-WSO2 Mashup test. My goal will be to create a mashup of all the wacky things I do so that I can keep track of it all. Boards, blogs, mailing lists, and stuff.

    beren

  3. jkw says:

    If you’ve had issues with bool casting etc you might want to use === instead of ==. That’s a common mistake I’ve seen in the past.

  1. January 13, 2008

    […] rob wrote an interesting post today onHere’s a quick excerptAs I continue on with Drupal I’m also beginning to digest PHP. I’ve worked with just about every programming language there is: Java, C, C++, Cold Fusion, Python, Perl, and even Fortran. I find scripting languages an excellent choice for web programming. However there is always a few tricks that you need to know – and these are easy to forget. I’m going to use this post as a place to “remember” these. Once I get enough I’m going to turn this into a page. If you have any tricks you’d like to contribute, just post a comment. Things To Remember with PHP 5: […]

  2. January 14, 2008

    […] Learning PHP – Things to Remember By berenerchamion 3-tier Development with PHP; PHP Manual; PHP Function Quick Reference; PDO MySQL Introduction ; PDO Tutorial. I’ll update this as I continue to learn more about PHP. My main focus will be on developing database applications and looking … Tarn Aeluin – http://tarnaeluin.wordpress.com […]

  3. January 14, 2008

    […] I?ve worked with just about every programming language there is: Java, C, C++, Cold Fusion, Python, Perl, and even Fortran. I find scripting languages an excellent choice for web programming. However there is always a few tricks that … read more […]

  4. April 28, 2008

    […] and varying qualities of code in the modules on drupal.org. I’ve updated my article on key things to remember about PHP based on some of […]

Leave a Reply