I've been developing in PHP for a while now, mostly iZeit, my PHP calendar script, but also the odd smaller script and I've picked up a few things along the way.
Quotes vs. Double Quotes
Anything in double quotes is parsed by PHP and variables are replaced. So if you’re concatenating things, use single quotes instead:
$name = 'Bob'; echo 'Name is '.$name; // Name is Bob echo "Name is $name"; // Name is Bob echo 'Name is $name'; // Name is $name echo "Name is ".$name; /* Name is Bob, but wastes processing time because the non dynamic part of the statement is parsed for variables. */
Check whether a variable's set first
There are times when if you try to use a variable that isn't set, PHP will throw an error at you.
$param = isset($_GET['param']) ? $_GET['param'] : NULL;
I have no idea why they even added shorttags. Using <?php ?> instead of <? ?> will make your scripts run on alot more servers which don't have short tags enabled in php.ini.coding, optimization, php, tips