home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / db_error2.phpt < prev    next >
Encoding:
Text File  |  2004-10-01  |  3.1 KB  |  93 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(E_ALL);
  11.  
  12. function myfunc(&$obj) {
  13.     print 'myfunc here, obj='
  14.           . strtolower($obj->toString()) . "\n";
  15. }
  16. function myfunc2(&$obj) {
  17.     print 'myfunc2 here, obj='
  18.           . strtolower($obj->toString()) . "\n";
  19. }
  20. class myclass {
  21.     function myfunc(&$obj) {
  22.         print 'myclass::myfunc here, obj='
  23.           . strtolower($obj->toString()) . "\n";
  24.     }
  25. }
  26. function test_error_handler($errno, $errmsg, $file, $line, $vars) {
  27.     if (defined('E_STRICT')) {
  28.         if ($errno & E_STRICT
  29.             && (error_reporting() & E_STRICT) != E_STRICT) {
  30.             // Ignore E_STRICT notices unless they have been turned on
  31.             return;
  32.         }
  33.     } else {
  34.         define('E_STRICT', 2048);
  35.     }
  36.     $errortype = array (
  37.         E_ERROR => 'Error',
  38.         E_WARNING => 'Warning',
  39.         E_PARSE => 'Parsing Error',
  40.         E_NOTICE => 'Notice',
  41.         E_CORE_ERROR => 'Core Error',
  42.         E_CORE_WARNING => 'Core Warning',
  43.         E_COMPILE_ERROR => 'Compile Error',
  44.         E_COMPILE_WARNING => 'Compile Warning',
  45.         E_USER_ERROR => 'User Error',
  46.         E_USER_WARNING => 'User Warning',
  47.         E_USER_NOTICE => 'User Notice',
  48.         E_STRICT => 'Strict Notice',
  49.     );
  50.     $prefix = $errortype[$errno];
  51.     print strtolower("$prefix: $errmsg in " . basename($file)
  52.                      . " on line XXX\n");
  53. }
  54.  
  55. $obj = new myclass;
  56.  
  57. $dbh = DB::factory("mysql");
  58.  
  59. print "default: ";
  60. $e = $dbh->raiseError("return testing error");
  61. print strtolower($e->toString()) . "\n";
  62.  
  63. print "global default: ";
  64. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc2");
  65. $e = $dbh->raiseError("global default test");
  66.  
  67. $dbh->setErrorHandling(PEAR_ERROR_PRINT);
  68. print "mode=print: ";
  69. $e = $dbh->raiseError("print testing error");
  70. print "\n";
  71.  
  72. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc");
  73. print "mode=function callback: ";
  74. $e = $dbh->raiseError("function callback testing error");
  75.  
  76. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, array($obj, "myfunc"));
  77. print "mode=object callback: ";
  78. $e = $dbh->raiseError("object callback testing error");
  79.  
  80. set_error_handler("test_error_handler");
  81. $dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
  82. print "mode=trigger: ";
  83. $e = $dbh->raiseError("trigger testing error");
  84.  
  85. ?>
  86. --EXPECT--
  87. default: [db_error: message="db error: return testing error" code=-1 mode=return level=notice prefix="" info=""]
  88. global default: myfunc2 here, obj=[db_error: message="db error: global default test" code=-1 mode=callback callback=myfunc2 prefix="" info=""]
  89. mode=print: DB Error: print testing error
  90. mode=function callback: myfunc here, obj=[db_error: message="db error: function callback testing error" code=-1 mode=callback callback=myfunc prefix="" info=""]
  91. 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=""]
  92. mode=trigger: user notice: db error: trigger testing error in pear.php on line xxx
  93.