</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/3737139/reference-what-does-this-symbol-mean-in-php" dir="ltr">Reference — What does this symbol mean in PHP?</a>
<span class="question-originals-answer-count">
(18 answers)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2013-11-19 18:48:16Z" class="relativetime">6 years ago</span>.</div>
</div>
</aside>
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:
Explanation for special syntax
</div>
<?= ?>
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.