home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / db_error2.phpt < prev    next >
Encoding:
Text File  |  2004-03-24  |  2.9 KB  |  89 lines

  1. --TEST--
  2. DB::Error 2
  3. --SKIPIF--
  4. <?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
  5. --FILE--
  6. <?php
  7. require_once './include.inc';
  8. require_once 'DB.php';
  9.  
  10. error_reporting(4095);
  11.  
  12. function myfunc(&$obj) {
  13.     print "myfunc here, obj=".$obj->toString()."\n";
  14. }
  15. function myfunc2(&$obj) {
  16.     print "myfunc2 here, obj=".$obj->toString()."\n";
  17. }
  18. class myclass {
  19.     function myfunc(&$obj) {
  20.         print "myclass::myfunc here, obj=".$obj->toString()."\n";
  21.     }
  22. }
  23. function test_error_handler($errno, $errmsg, $file, $line, $vars) {
  24.     if (defined('E_STRICT')) {
  25.         if ($errno & E_STRICT
  26.             && (error_reporting() & E_STRICT) != E_STRICT) {
  27.             // Ignore E_STRICT notices unless they have been turned on
  28.             return;
  29.         }
  30.     } else {
  31.         define('E_STRICT', 2048);
  32.     }
  33.     $errortype = array (
  34.         E_ERROR => 'Error',
  35.         E_WARNING => 'Warning',
  36.         E_PARSE => 'Parsing Error',
  37.         E_NOTICE => 'Notice',
  38.         E_CORE_ERROR => 'Core Error',
  39.         E_CORE_WARNING => 'Core Warning',
  40.         E_COMPILE_ERROR => 'Compile Error',
  41.         E_COMPILE_WARNING => 'Compile Warning',
  42.         E_USER_ERROR => 'User Error',
  43.         E_USER_WARNING => 'User Warning',
  44.         E_USER_NOTICE => 'User Notice',
  45.         E_STRICT => 'Strict Notice',
  46.     );
  47.     $prefix = $errortype[$errno];
  48.     print "$prefix: $errmsg in " . basename($file) . " on line XXX\n";
  49. }
  50.  
  51. $obj = new myclass;
  52.  
  53. $dbh = DB::factory("mysql");
  54.  
  55. print "default: ";
  56. $e = $dbh->raiseError("return testing error");
  57. print $e->toString() . "\n";
  58.  
  59. print "global default: ";
  60. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc2");
  61. $e = $dbh->raiseError("global default test");
  62.  
  63. $dbh->setErrorHandling(PEAR_ERROR_PRINT);
  64. print "mode=print: ";
  65. $e = $dbh->raiseError("print testing error");
  66. print "\n";
  67.  
  68. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc");
  69. print "mode=function callback: ";
  70. $e = $dbh->raiseError("function callback testing error");
  71.  
  72. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, array($obj, "myfunc"));
  73. print "mode=object callback: ";
  74. $e = $dbh->raiseError("object callback testing error");
  75.  
  76. set_error_handler("test_error_handler");
  77. $dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
  78. print "mode=trigger: ";
  79. $e = $dbh->raiseError("trigger testing error");
  80.  
  81. ?>
  82. --EXPECT--
  83. default: [db_error: message="DB Error: return testing error" code=-1 mode=return level=notice prefix="" info=""]
  84. global default: myfunc2 here, obj=[db_error: message="DB Error: global default test" code=-1 mode=callback callback=myfunc2 prefix="" info=""]
  85. mode=print: DB Error: print testing error
  86. mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback testing error" code=-1 mode=callback callback=myfunc prefix="" info=""]
  87. mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback testing error" code=-1 mode=callback callback=myclass::myfunc prefix="" info=""]
  88. mode=trigger: User Notice: DB Error: trigger testing error in PEAR.php on line XXX
  89.