errors = [null]; if ($contextNode === null) { $contextNode = $this->document->documentElement; } set_error_handler([$this, 'addError'], E_WARNING); $nodeList = $this->query($expression, $contextNode); restore_error_handler(); $exception = array_pop($this->errors); if ($exception) { throw $exception; } return $nodeList; } /** * Adds an error to the stack of errors * * @param int $errno * @param string $errstr * @param string $errfile * @param int $errline * @return void */ public function addError($errno, $errstr = '', $errfile = '', $errline = 0) { $lastError = end($this->errors); $this->errors[] = new ErrorException( $errstr, 0, $errno, $errfile, $errline, $lastError ); } }