Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the '@' prefix do in PHP? [duplicate]

Tags:

php

prefix

What does the '@' symbol do in the following code?

@mkdir(ROOT. "cache/"); 
like image 488
Rich Turner Avatar asked Jan 11 '11 01:01

Rich Turner


People also ask

What is prefix in PHP?

PHPServer Side ProgrammingProgramming. The '@' symbol suppresses errors from getting displayed on the screen. PHP supports an error control operator, i.e the sign (@). When it is prepended to an expression in PHP, error messages that could get generated when it uses that expression will be ignored.

What is Call by reference in PHP?

In case of PHP call by reference, actual value is modified if it is modified inside the function. In such case, you need to use & (ampersand) symbol with formal arguments. The & represents reference of the variable. Let's understand the concept of call by reference by the help of examples.

What is reference variable PHP?

A PHP reference is an alias, which allows two different variables to write to the same value. In PHP, an object variable doesn't contain the object itself as value. It only contains an object identifier which allows object accessors to find the actual object.


1 Answers

It suppresses errors from displaying:

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.

If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable $php_errormsg. This variable will be overwritten on each error, so check early if you want to use it.

As noted in the comments, I too cannot imagine a reason to actually use this functionality -- write code that deals appropriately with error states/conditions.

like image 92
Mark Elliot Avatar answered Oct 19 '22 09:10

Mark Elliot