Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

David Otton's Blog:
Stupid PHP Tricks: Illegal Variable Names
Aug 22, 2008 @ 18:47:52

David Otton has shared another of his "stupid PHP tricks" on his blog today. This one looks at illegal variable names that don't match the "can't start with a number" rule the manual points out.

A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*'

Technically, you can get around this in two different ways - variable varaibles and the more complex notation with curly braces. He points to the compact function for proof that they're set.

tagged: variable trick illegal name compact curlybrace

Link:

PHP-Coding-Practices.com:
Try-Catch Syntax Weirdness
Jun 22, 2007 @ 18:28:00

In working with his code recently, Tim Koschuetzki noticed something odd with a block of try/catch code:

I just noticed today, that PHP's try catch blocks require curly braces. Anybody has an idea why it is like that? I have used curly braces by default up until now, so I just stumbled upon this weirdness today.

He includes two examples, one with a curly brace after the catch clause and the other without. This is different than several other control structures (like ifs) that don't require the curly brace when there's only the one line following it.

tagged: try catch curlybrace require try catch curlybrace require

Link:

PHP-Coding-Practices.com:
Try-Catch Syntax Weirdness
Jun 22, 2007 @ 18:28:00

In working with his code recently, Tim Koschuetzki noticed something odd with a block of try/catch code:

I just noticed today, that PHP's try catch blocks require curly braces. Anybody has an idea why it is like that? I have used curly braces by default up until now, so I just stumbled upon this weirdness today.

He includes two examples, one with a curly brace after the catch clause and the other without. This is different than several other control structures (like ifs) that don't require the curly brace when there's only the one line following it.

tagged: try catch curlybrace require try catch curlybrace require

Link:


Trending Topics: