0

I found this tutorial on making a try it editor for a website.
I understood everything in the code except the @ in the result.php:

Result.php

<?php 
$myCode = @$_REQUEST["code"];
print $myCode ;
?>  

Also I tried removing it from the code and nothing changed, so what does it do?

Community
  • 1
  • 1

2 Answers2

1

It ignores/suppresses error messages - see Error Control Operators in the PHP manual.

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 you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @.

so any error in $myCode = @$_REQUEST["code"]; will be ignored.

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
1

@ is a PHP error control operator

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

Reference

http://php.net/manual/en/language.operators.errorcontrol.php

Example

<?php
/* Intentional file error */
$my_file = @file ('non_existent_file') or
    die ("Failed opening file: error was '$php_errormsg'");

// this works for any expression, not just functions:
$value = @$cache[$key];
// will not issue a notice if the index $key doesn't exist.

?>
Sundar
  • 4,580
  • 6
  • 35
  • 61