Archive

Archive for September, 2006

/* a timer class */

September 16th, 2006 No comments

The code: Source File in text
I usually use this to check the generation time for any page. There are critical applications which we are developing and will need less than a milli second generation time.

PHP Ajax Frameworks – Ajax Patterns

September 15th, 2006 No comments

Some web application frameworks with php and ajax which are open and available is discussed in this page. I might some time use one of these or try and make one framework of my own.
PHP Ajax Frameworks – Ajax Patterns

Categories: Uncategorized Tags:

PHP – Quotes or No quotes in associative Array?

September 14th, 2006 No comments

Our team was having a debate on why we should put a ‘ (single quote) when referencing arrays in php. Well what is the problem if we use $_SESSION[key], instead of $_SESSION['key'].

Well when you think that when encountering non functions or keywords, php tries to evaluate it as a declared constant. So referencing $_SESSION['key'] would be better against $_SESSION[key], unless we have defined the constant key and want to use the value of key.

Categories: PHP, Tips Tags: ,

Single Quotes vs Double Quotes!

September 14th, 2006 No comments

I recommend using ‘ (single quotes) when programming with PHP; Always use ‘ (single quotes) unless you need the features of ” (double quotes). You might think it’s much easier to write code as:

echo "Today is the $day of $month";

However, using single quotes forces variables to be outside the quotes; instead when you use the ” (double quotes), forces php to evaluate the string, where as with ‘ (single quotes), the string content is taken as such.

Categories: PHP, Tips Tags: ,

error_reporting(E_ALL); make code faster

September 14th, 2006 2 comments

The single most important thing I tell people who use PHP is to turn error reporting to its maximum level. Why would I want to do this? Generally the error reporting is set at a level that will hide many little things like:

  • declaring a variable ahead of time,
  • referencing a variable that is not available in that segment of code, or
  • using a define that is not set

These factors might not seem like that big a deal — until you develop structured or object oriented programs with functions and classes. Too often, writing code with the error reporting turned up high would cost you hours as you scoured long functions that didn’t work because a variable was misspelled or not accessible.

PHP won’t tell you anything in that case it’ll just create the new variable for you and initialize it to zero. The remedy is to put the following line at the top of every PHP document as you develop:

error_reporting(E_ALL);

It simply forces the error reporting to be at its highest level. Try putting this line in other PHP programs, and more often than not you’ll receive a barrage of warning messages that identify all the potentially wrong elements of the code.

Eventually this when enabled, will force you to write cleaner, structured and fast code.

Categories: PHP, Tips Tags: , ,