Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Error Suppression Operator (@) as a shortcut for isset(). Bad Practice? [closed]
  2. if ( isset($_SESSION) && isset($_SESSION['myVariable']) && $_SESSION['myVariable'] == true )
  3.   echo "myVariable is True!";
  4.        
  5. if ( @$_SESSION['myVariable'] == true )
  6.   echo "myVariable is True!";
  7.        
  8. session_start();
  9. $count = 0;
  10. $start = microtime(true);
  11.  
  12. for($i=0;$i<10000;$i++){
  13.     if ( @$_SESSION['myVariable'] == true ){
  14.       $count++;
  15.     }
  16. }
  17. echo "Took ".(microtime(true)-$start)." Microseconds with error supression.<br />";
  18.  
  19. $count = 0;
  20. $start = microtime(true);
  21. for($i=0;$i<10000;$i++){
  22.     if ( isset($_SESSION) && isset($_SESSION['myVariable']) && $_SESSION['myVariable'] == true ){
  23.       $count++;
  24.     }
  25. }
  26. echo "Took ".(microtime(true)-$start)." Microseconds with formal checks.<br />";
  27.        
  28. Took 0.010571002960205 Microseconds with error supression.
  29. Took 0.002446174621582 Microseconds with formal checks.
  30.        
  31. Took 0.0098469257354736 Microseconds with error supression.
  32. Took 0.00094795227050781 Microseconds with formal checks.
  33.        
  34. if (!@chmod($someFileUri)) {
  35.     throw new Exception('Cannot change mode plus some extra stuff...');
  36. }