コード例 #1
0
ファイル: Lexer.php プロジェクト: iarmoa/gaia
 protected function resetErrors()
 {
     if (function_exists('error_clear_last')) {
         error_clear_last();
     } else {
         // set error_get_last() to defined state by forcing an undefined variable error
         set_error_handler(function () {
             return false;
         }, 0);
         @$undefinedVariable;
         restore_error_handler();
     }
 }
コード例 #2
0
 public static function globalErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
 {
     if (!error_reporting()) {
         if (PHP_MAJOR_VERSION >= 7) {
             error_clear_last();
         }
         return false;
     }
     //    self::globalExceptionHandler (new PHPError($errno, $errstr, $errfile, $errline, $errcontext));
     if (self::$nextErrorHandler) {
         call_user_func(self::$nextErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext);
     }
     throw new PHPError($errstr, 0, $errno, $errfile, $errline, null, $errcontext);
 }
コード例 #3
0
ファイル: MemcacheDriver.php プロジェクト: kuria/cache
 public function exists($key)
 {
     // reset last error
     if (PHP_MAJOR_VERSION >= 7) {
         error_clear_last();
     } else {
         set_error_handler('min', 0);
         // never called
         @trigger_error(null);
         restore_error_handler();
     }
     // there is no "exists()" method in memcache - ugly hack follows
     $result = @$this->memcache->increment($key, 0);
     // if the result is not FALSE, then the entry exists (and is an integer)
     // if the result is FALSE and no error has been raised, the entry does not exist
     // if the result is FALSE and an error has been raised, the entry exists (and is not an integer)
     return false !== $result || ($error = error_get_last()) && $error['file'] === __FILE__ && $error['line'] === __LINE__ - 10;
 }
コード例 #4
0
ファイル: ErrorHandler.php プロジェクト: webkingashu/phpdox
 public function clearLastError()
 {
     if (function_exists('error_clear_last')) {
         error_clear_last();
     } else {
         set_error_handler(function () {
             return false;
         }, 0);
         @trigger_error('');
         restore_error_handler();
     }
 }
コード例 #5
0
ファイル: errors.php プロジェクト: t-web/doeqs_new
function error_get_clear()
{
    $a = error_get_last();
    error_clear_last();
    return $a;
}
コード例 #6
0
 /**
  * Validates regular expression
  *
  * @param string $path   path to config
  * @param array  $values config values
  *
  * @return array
  */
 public static function validateRegex($path, $values)
 {
     $result = array($path => '');
     if (empty($values[$path])) {
         return $result;
     }
     if (function_exists('error_clear_last')) {
         /* PHP 7 only code */
         error_clear_last();
         $last_error = null;
     } else {
         // As fallback we trigger another error to ensure
         // that preg error will be different
         @strpos();
         $last_error = error_get_last();
     }
     $matches = array();
     // in libraries/ListDatabase.php _checkHideDatabase(),
     // a '/' is used as the delimiter for hide_db
     @preg_match('/' . Util::requestString($values[$path]) . '/', '', $matches);
     $current_error = error_get_last();
     if ($current_error !== $last_error) {
         $error = preg_replace('/^preg_match\\(\\): /', '', $current_error['message']);
         return array($path => $error);
     }
     return $result;
 }
コード例 #7
0
<?php

// drop startup errors
if (function_exists('error_clear_last')) {
    error_clear_last();
}
error_reporting(0);
/** @var Base $f3 */
$f3 = (require 'src/base.php');
error_reporting(-1);
$f3->set('DEBUG', 2);
$f3->set('HIGHLIGHT', false);
$f3->set('CACHE', 'folder=tmp/cache/');
$f3->set('UI', 'ui/');
$f3->set('ONERROR', function ($f3) {
    echo $f3->get('ERROR.code') . ': ' . $f3->get('ERROR.text') . "\n" . $f3->get('ERROR.trace');
});
$f3->set('DBS', array('mysql:host=localhost;port=3306;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass'));
// http: //www.techempower.com/benchmarks/#section=code
// JSON test
$f3->route('GET /json', function ($f3) {
    /** @var Base $f3 */
    header("Content-type: application/json");
    echo json_encode(array('message' => 'Hello, World!'));
});
// DB RAW test database-single-query
$f3->route('GET /db', function ($f3, $params) {
    /** @var Base $f3 */
    $dbc = $f3->get('DBS');
    $db = new \DB\SQL($dbc[0], $dbc[1], $dbc[2], array(\PDO::ATTR_PERSISTENT => TRUE));
    $id = mt_rand(1, 10000);
コード例 #8
0
ファイル: Proxy.php プロジェクト: jpauli/PHP-Proxy-Pattern
 /**
  * Generic proxy method
  * The hash is based on array(subjectclass, methodcalled, array(params))
  *  to avoid collisions
  *
  * @param string $meth
  * @param array $args
  * @return mixed
  * @throws DomainException
  * @throws RuntimeException
  * @throws BadMethodCallException
  */
 public function __call($meth, $args)
 {
     if (!$this->cacheObject || !$this->subjectObject) {
         throw new \DomainException("Cache object or subject object not set");
     }
     $hash = $this->makeHash([get_class($this->subjectObject), $meth, $args]);
     if ($this->cacheObject->has($hash)) {
         $this->setCacheHit($hash);
         return $this->cacheObject->get($hash);
     }
     if (method_exists($this->subjectObject, $meth)) {
         error_clear_last();
         try {
             $return = @$this->subjectObject->{$meth}(...$args);
         } catch (\Exception $e) {
             throw new \BadFunctionCallException("Proxy method call error", null, $e);
         }
         $error = error_get_last();
         if ($error) {
             throw new \RuntimeException($error['message']);
         }
         $this->cacheObject->set($hash, $return);
         $this->cacheHits[$hash] = 0;
         return $return;
     }
     throw new \BadMethodCallException("Method {$meth} doesnt exists");
 }
コード例 #9
0
 /**
  * Converts PHP < 7 errors to ErrorExceptions.
  *
  * @internal
  * @param int    $code
  * @param string $msg
  * @param string $file
  * @param int    $line
  * @return bool
  * @throws \ErrorException
  */
 public function errorHandler($code = null, $msg = null, $file, $line)
 {
     if (!error_reporting()) {
         if (PHP_MAJOR_VERSION >= 7) {
             error_clear_last();
         }
         return false;
     }
     throw new \ErrorException($msg, $code, 1, $file, $line);
 }
コード例 #10
0
/**
 * Outputs a formatted representation of the given arguments to the browser, clearing any existing output.
 * <p>This is useful for debugging.
 */
function dump()
{
    error_clear_last();
    if (!isCLI()) {
        echo "<pre>";
    }
    ob_start();
    call_user_func_array('var_dump', func_get_args());
    $o = ob_get_clean();
    $o = str_replace('[', '[', $o);
    // to prevent colision with color escape codes
    $o = preg_replace('/\\{\\s*\\}/', '{}', $o);
    // condense empty arrays
    $o = preg_replace('/":".*?":(private|protected)/', color('dark grey', ':$1'), $o);
    // condense empty arrays
    // Applies formatting if XDEBUG is not installed
    $SEP = color('dark grey', '|');
    $o = preg_replace_callback('/^(\\s*)\\["?(.*?)"?\\]=>\\n\\s*(\\S+) *(\\S)?/m', function ($m) use($SEP) {
        $m[] = '';
        list(, $space, $prop, $type, $next) = $m;
        $z = explode('(', $type, 2);
        if (count($z) > 1) {
            list($type, $len) = $z;
            $len = color('dark cyan', " ({$len}");
            $type = $type . $len;
        }
        $num = ctype_digit($prop[0]);
        return $space . $SEP . color('dark yellow', str_pad($prop, $num ? 4 : 22, ' ', $num ? STR_PAD_LEFT : STR_PAD_RIGHT)) . " {$SEP} " . color('dark green', str_pad($type, 25, ' ')) . (strlen($next) ? "{$SEP} {$next}" : '');
    }, $o);
    $o = preg_replace('/[\\{\\}§\\]]/', color('red', '$0'), $o);
    $o = str_replace('"', color('dark cyan', '"'), $o);
    $o = preg_replace('/^(\\s*object)\\((.*?)\\)(.*?(?=\\{))/m', '$1(' . color('dark purple', '$2') . ')' . color('dark cyan', '$3'), $o);
    $o = preg_replace('/^(\\s*\\w+)\\((\\d+)\\)/m', str_pad(color('dark green', '$1') . color('dark cyan', ' ($2)'), 31, ' '), $o);
    echo $o;
    if (!isCLI()) {
        echo "</pre>";
    }
}
コード例 #11
0
 /**
  * @param DefinitionInterface $definition
  * @return bool
  */
 public function runTestDefinition(DefinitionInterface $definition) : bool
 {
     $context = new Context();
     $this->eventDispatcher->dispatch(self::EVENT_TEST_WILL_RUN, new Event($definition, $context));
     $this->prepareTestRunnerForDefinition($definition);
     $exception = null;
     set_error_handler([$this, 'handleError']);
     error_clear_last();
     try {
         $this->performTest($definition, $context);
     } catch (\Error $exception) {
     } catch (\Exception $exception) {
     }
     $this->environment->reset();
     $this->eventDispatcher->dispatch(self::EVENT_TEST_DID_RUN, new Event($definition, $context));
     if ($exception !== null) {
         $this->printException($definition, $exception);
         return false;
     }
     $lastError = error_get_last();
     if (!$lastError) {
         $this->printSuccess($definition);
         return true;
     }
     $this->printException($definition, $this->createExceptionFromError($lastError));
     return false;
 }