Search code examples
phpprefix

What does the '@' prefix do in PHP?


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

@mkdir(ROOT. "cache/");

Solution

  • 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.