Пример #1
0
 function actionDefault()
 {
     // Create new instance of MyClass and execute test()
     $my = new MyClass();
     $res = $my->test();
     // Check for errors
     while ($err = YDError::catchError($res)) {
         YDDebugUtil::dump($err, '$err');
         $err->level;
         // 3
         $err->name;
         // fatal
         $err->message;
         // We couldn't do something
         $err->file;
         // ..../MyClass.php
         $err->line;
         // x
     }
     // We can also set automatic reporting
     YDError::reporting(YD_ERROR_FATAL);
     // display fatals, warnings and notices
     YDError::reporting(YD_ERROR_WARNING);
     // display warnings and notices
     YDError::reporting(YD_ERROR_NOTICE);
     // display notices
     YDError::reporting(YD_ERROR_NONE);
     // don't display errors
     // We can get the last errors array
     $errors = YDError::getAll();
     YDDebugUtil::dump($errors, '$errors');
     // Or we could dump the error
     if ($err = YDError::catchError($res)) {
         $err->dump();
     }
 }
Пример #2
0
 /**
  *  This function creates an YDError object and store it.
  *
  *  @param  $level    The error level.
  *  @param  $message  The error message.
  *  @param  $custom   (optional)
  *
  *  @returns     An YDError object.
  *  
  *  @internal
  *  @static
  */
 function _error($level, $message, $custom = null)
 {
     // Get the current stack
     $stack = debug_backtrace();
     // Get level names
     $levels = YDConfig::get('YD_ERROR_LEVELS');
     // Get the complete stack trace
     $stacktrace = YD_CRLF;
     foreach (array_slice($stack, 1) as $t) {
         $stacktrace .= '    @ ';
         if (isset($t['file'])) {
             $stacktrace .= basename($t['file']) . ':' . $t['line'];
         } else {
             $stacktrace .= basename(YD_SELF_FILE);
         }
         $stacktrace .= ' -- ';
         if (isset($t['class'])) {
             $stacktrace .= $t['class'] . $t['type'];
         }
         $stacktrace .= $t['function'];
         if (isset($t['args']) && sizeof($t['args']) > 0) {
             $stacktrace .= '(...)';
         } else {
             $stacktrace .= '()';
         }
         $stacktrace .= YD_CRLF;
     }
     // Create the error object
     $error = new YDError($level, $message, $stack[1]['file'], $stack[1]['line'], $stack[2]['class'] . $stack[2]['type'] . $stack[2]['function'], $stacktrace, $custom);
     // Store the error object on the global errors array
     YDConfig::set(YDConfig::get('YD_ERROR_STORE_NAME'), array_merge(YDError::getAll(), array($error)));
     // If reporting for this level is on, dump the error
     if ($level <= YDConfig::get('YD_ERROR_REPORTING')) {
         echo $error->_dump(true, 2);
         if ($level == YD_ERROR_FATAL) {
             die;
         }
     }
     // Return the error object
     return $error;
 }