@$ in PHP

hi

what is a @ symbol before a $ in a variable declaration

example:   @$variableTest
LVL 1
joyacv2Asked:
Who is Participating?
 
Ray PaseurCommented:
It's almost certainly a mistake!  The correct approach is to avoid error suppression, and instead fix the underlying condition that could raise a message.

Think about this for a moment.  What if you used error suppression on a function call that created a Fatal error?  Your script would fail with a run-time error, possibly after damaging some of your data model, and you would have no way of knowing why the error occurred or where the script was in the progress of completing its task.

This by itself is meaningless: @$variableTest.  The @ suppresses messages and the simple statement of a variable name cannot issue a message.  More often we see it used in something like this:

$fp = @fopen(...)

In that context, the message about "file not found" can be suppressed.  Other parts of the PHP script will need to deal with the missing file.
0
 
GaryCommented:
Suppress any error
http://php.net/manual/en/language.operators.errorcontrol.php

In that case if the var doesn't exist then the code won't burp
0
 
Dave BaldwinFixer of ProblemsCommented:
I agree with Ray.  I don't think I have Any code that uses a '@' to suppress error reporting... because it does not suppress the error, it just fails to 'report' it.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Ray PaseurCommented:
Very well put, Dave.  It's like you still ran over the cat, you just didn't tell anyone.  No problem till someone says, "Here kitty" or notices that the mice are eating all of the cheese.
0
 
Mark BradyPrincipal Data EngineerCommented:
@Ray ..
No problem till someone says, "Here kitty" or notices that the mice are eating all of the cheese.

Hahahaha nice!
0
 
Ray PaseurCommented:
Thanks for the points and thanks for using EE.  Going forward, don't feel uncomfortable about sharing the points among the answers that contribute to your understanding.  Both Gary and Dave added good information here, too!

Best wishes for new year 2014, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.