From cd2ed5526ed850cd10e555b1a6c1059a9c1fe5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Campitelli?= <1877191+vcampitelli@users.noreply.github.com> Date: Thu, 21 Mar 2019 15:10:55 -0300 Subject: [PATCH 1/3] ErrorHandler: Renaming \Exception to \Throwable because PHP 7 throws Errors too --- php/ErrorHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/ErrorHandler.php b/php/ErrorHandler.php index 7c5f1a7..d7d4159 100644 --- a/php/ErrorHandler.php +++ b/php/ErrorHandler.php @@ -40,9 +40,9 @@ public static function onError($code, $message, $file, $line, $context) /** * Display uncaught exception in JSON. * - * @param \Exception $exception + * @param \Throwable $exception */ - public static function onException(\Exception $exception) + public static function onException(\Throwable $exception) { die( json_encode( From ede349c0ab53e903036768bcd80f236679a2f88b Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Wed, 14 Oct 2020 21:14:23 +0200 Subject: [PATCH 2/3] Fix deprecation warning for __toString() call for PHP >= 7.1 ReflectionNamedType::__toString() was deprecated in PHP 7.1.0 in favor of ReflectionNamedType::getName() and the deprecation warning will break the JSON output --- php/services/Tools.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/services/Tools.php b/php/services/Tools.php index a3218f2..496dd25 100644 --- a/php/services/Tools.php +++ b/php/services/Tools.php @@ -212,7 +212,7 @@ protected function getMethodArguments(ReflectionFunctionAbstract $function) ); $result['return']['type'] = method_exists($function, 'getReturnType') && $function->hasReturnType() // PHP7 - ? $function->getReturnType()->__toString() + ? (version_compare(PHP_VERSION, '7.1.0', '>=') ? $function->getReturnType()->getName() : $function->getReturnType()->__toString()) : $result['return']['type'] ; From fafd74340888c3ce6c4ad3af68225e67e7fd7393 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Thu, 11 Feb 2021 00:18:09 +0100 Subject: [PATCH 3/3] ErrorHandler: call onException from onError to work around PHP #66216 parsing files including broken require_once (e.g. path can not be resolved) will trigger an error which is handled by onError converting it to an ErrorException and throwing it again. This *should* then be caught by onException to convert and print this as JSON and exit. But due to https://bugs.php.net/bug.php?id=66216 this does not happen and the parser exits an empty output which results in another Exception in php-proxy.coffee trying to parse the empty string as JSON. --- php/ErrorHandler.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/php/ErrorHandler.php b/php/ErrorHandler.php index d7d4159..53b0027 100644 --- a/php/ErrorHandler.php +++ b/php/ErrorHandler.php @@ -29,12 +29,11 @@ public static function register() set_exception_handler('Peekmo\AtomAutocompletePhp\ErrorHandler::onException'); } - /** - * @throws ErrorException on any error. - */ public static function onError($code, $message, $file, $line, $context) { - throw new \ErrorException($message, $code, 1, $file, $line); + // call onException directly instead of throw'ing + // to work around https://bugs.php.net/bug.php?id=66216 + self::onException(new \ErrorException($message, $code, 1, $file, $line)); } /**