Simple assertion handler


/ Published in: PHP
Save to your folder(s)

This is a useful debugging utility in lieu of Exception objects


Copy this code and paste it in your HTML
  1. <?php
  2. // FILE: assertion.php
  3. // DESCRIPTION: Handles assertions where the Exception object is not used
  4. // ---------------------------------
  5. // Mon Mar 03 21:36:54 EST 2008
  6.  
  7. /**
  8.  * USAGE:
  9.  * assert(string code)
  10.  * The code should be passed as a string similar to the way eval() is invoked.
  11.  */
  12.  
  13. assert_options(ASSERT_CALLBACK, 'assertion_handler');
  14. assert_options(ASSERT_ACTIVE, 1);
  15. assert_options(ASSERT_WARNING, 0);
  16. assert_options(ASSERT_QUIET_EVAL, 1);
  17.  
  18. function assertion_handler($file, $line, $code)
  19. {
  20. if (true === DEBUG_MODE) {
  21.  
  22. $msg = <<<EOT
  23. <pre style="background-color:#FF0000;color:#FFFFFF;font-weight:bold;padding:8px;">
  24. FAILED ASSERTION
  25. File: {$file}
  26. Line: {$line}
  27. Code: {$code}
  28. </pre>
  29. EOT;
  30.  
  31. print $msg;
  32. }
  33. }
  34. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.