0

I'am include some files of my website by mvc.php. And I want that if there are errors in PHP code - user see my error page instead of exceptions.

I tried to catch errors with try/catch, but include errors skips it

try {
    include '../index.php';
} catch (Exception $e) {
    include 'errors/error501.php';
}
return;

With ths code there is just an exception text of my corrupted file:

Parse error: syntax error, unexpected '/', expecting end of file in W:\domains\amelia.lc\dev\index.php on line 87

I tried to check file with php_check_syntax, but this function were deleted from PHP

How can i solve it?

  • Include(‘filetoinclude.php’) – Lelio Faieta Sep 10 '20 at 16:47
  • Lelio Faieta, nothing changed – USSURATONCAHI Sep 10 '20 at 16:51
  • Not sure of the exact scenario that leads to PHP files being changed and deployed to production without being even run but [overtrue / phplint](https://github.com/overtrue/phplint) is a lovely command-line utility for batch linting. – Álvaro González Sep 10 '20 at 16:53
  • Álvaro González, how i gonna use command line on the hosting? – USSURATONCAHI Sep 10 '20 at 16:59
  • You can use PuTTY, `system()`, `exec()`... or check code locally before deploying since the language syntax is the same in your local PC and in your internet host. But, as I said, I don't know the details of your scenario. Why do those PHP source code files appear randomly in your server? Are they uploaded by users? – Álvaro González Sep 11 '20 at 06:36

0 Answers0