·  PHP – Syntax – Keywords – At @

 

Info:

  - @ is error control operator.

    When perpended to an expression, any error messages that might be generated by that expression will be ignored.

  - If the track_errors feature is enabled, generated error message will be saved in the variable $php_errormsg.

    This variable will be overwritten on each error.

  - This tutorial is based on http://php.net/manual/en/language.operators.errorcontrol.php.

 

- Example:

  - Edit php.ini: track_errors = On

 

    Test.php

    <?php

      //OPEN FILE.

      $fp = @fopen("/home/ivor4/Installed/Programming/Workspace/PHP_Test/test.txt", 'a');

      //CHECK ERRORS.

      if($fp==false) {

        print("Unable to open or create file with error:\n$php_errormsg");

        exit(1);

      }

   

      //ADD LINE.

      flock ($fp, LOCK_EX);

      fwrite($fp, "Third line 34.\n");

      flock ($fp, LOCK_UN);

      //CLOSE FILE.

      fclose($fp);

    ?>

   

    output

    Unable to open or create file with error:

    fopen(/home/ivor4/Installed/Programming/Workspace/PHP_Test/test.txt): failed to open stream: No such

    file or directory

   

    output (without @)

    PHP Warning: fopen(/home/ivor4/Installed/Programming/Workspace/PHP_Test/test.txt): failed to open

    stream: No such file or directory in /home/ivor/Installed/Programming/Workspace/PHP_Test/Error.php

    on line 4

    Unable to open or create file with error: