1

I'm following a PHP/AJAX tutorial on form validation. (I'm new to php!).

Could someone explain the syntax of this line:

<?=@$_REQUEST['username']?>

The context is the value attribute of an input field.

I know how $_REQUEST works. I just don't get the <?=@ part. I understand <? can be used in lieu of <?php (but isn't always supported!) and <?=$variable?> is special syntax for echoing variables. What does the @ symbol do?

Thanks.

Links:

Form validation tutorial

Explanation for special syntax

Patrick Borkowicz
  • 1,166
  • 9
  • 19

1 Answers1

6

<?= ?> is the short echo syntax. <?=$var?> is equivalent to <?php echo $var; ?>.

From the PHP manual:

echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.

@ is the error suppression operator. When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

In short, <?=@$_REQUEST['username']?> will try to print out the value of $_REQUEST['username'] (without ouputting any errors). It's not a good practice and shouldn't be used in your code. If you don't want to display the errors, turn off display_errors in your php.ini configuration and log them instead.

Amal Murali
  • 70,371
  • 17
  • 120
  • 139