Monday, September 11, 2006

Shutup PHP @ $%!

OK.. I'm getting a bit carried away here.

I saw a bit of code in PHP like ..
$contents = @file_get_contents($filename);

But what is the @ before the function call?? As bad as I am with googling I was not able to get some good docs on this. The best info I got was from meeting notes which says that its called the shut-up operator.

So then I backtracked to the PHP manual and found Error Control Operators. The doc says..
"PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored."

Yet another example of a lazy programmer trying to code before reading docs

1 comment:

Anonymous said...

"Yet another example of a lazy programmer trying to code before reading docs"

It isn't. In PHP, the shut-up operator is virtually mandatory when opening files. Otherwise PHP will print error messages to the user of the software.