3v4l.org

run code in 300+ PHP versions simultaneously
<?php // GetUserFromApi and GetProductFromApi call for different data but both get the same error response exxception and error data // Both classes' controllers handle what is set inside the common exception "ErrorResponseException" class GetUserFromApi { /** * @throws ErrorResponseException */ function get() { try { return $this->getUserRepo->get(); } catch (HttpException $exception) { // Used by both classes - THE PROBLEM: not obvious this throws $this->handleHttpError->handle($exception); } } } class GetProductFromApi { /** * @throws ErrorResponseException */ function get() { try { return $this->getProductRepo->get(); } catch (HttpException $exception) { // Used by both classes - THE PROBLEM: not obvious this throws $this->handleHttpError->handle($exception); } } } class HandleHttpError { /** * @throws ErrorResponseException */ function handle(HttpException $exception) { // Extract data from HttpException, or set defaults if not exist // Use data to perform various tasks, then set relevant data in specific exception, log, and pass back (throw) $errorResponseException = new ErrorResponseException(various data from HttpException); $this->logger->error($errorResponseException); throw $errorResponseException; } }
Output for 8.0.1 - 8.0.17, 8.1.0 - 8.1.4
Parse error: syntax error, unexpected identifier "data", expecting ")" in /in/UcE0F on line 47
Process exited with code 255.
Output for 7.4.0 - 7.4.28
Parse error: syntax error, unexpected 'data' (T_STRING), expecting ')' in /in/UcE0F on line 47
Process exited with code 255.

preferences:
152.82 ms | 1288 KiB | 6 Q