Friday, January 7, 2011

What does the @ symbol do in PHP?

QUESTION
========

Can someone explain thise line of code to me, I cannot find a refernece in
the manual to using the @ symbol.

$this->Record = @pg_fetch_array($this->Query_ID, $this->Row++);


ANSWER
======

Adding the "@" symbol in front of any function call will suppress any
PHP-generated error messages from that function call. In general, this is
used to prevent users from seeing nasty error messages when you have
coded something incorrectly.

That means that if that function generates a non-fatal error (warning) it
will not display the warning message in your HTML, rather just return false
and let the program cope with it.


an @ symbol in front of the mysql_query function. Many functions, including mysql_query, automatically display ugly error messages when they fail. Placing the @ symbol (also known as the error suppression operator) in front of the function name tells the function to fail silently, and allows us to display our own, friendlier error message.

Source(s):

http://www.sitepoint.com/article/publishing-mysql-data-web
  • 4 years ago

No comments: