W Six
W Six

Reputation: 3

Localhost - PHP Include Not Showing Errors

I've just installed the latest version of Appserv ( 9.3.0 ), which includes:

Apache 2.4.41
PHP 7.3.10
MySQL 8.0.17
phpMyAdmin 4.9.1

I'm using Localhost as my root directory and trying to reuse old files to build a new website, but I'm noticing a problem.

I'm using the include() function, but there is a problem.

<?php include(file.php); ?> shows the contents of file.php, but, if I delete file.php, it doesn't give me an error message saying file.php could not be found. Why is this?

Upvotes: 0

Views: 1884

Answers (2)

W Six
W Six

Reputation: 3

In Windows 10, go to:

Start > Appserv > PHP Edit php.ini

Find line : display_errors Off and change to display_errors On

Save & Close

Start > AppServ > Apache Restart

Upvotes: 0

B&#228;r Ger
B&#228;r Ger

Reputation: 72

Answer to secondly:

include() on a non-existent file produces an error of type E_WARNING. For testing purposes simply add this line of code

error_reporting(1);

before using an include() statement.

For production you should avoid displaying any kind of errors. You can register your own error handler with set_error_handler().

set_error_handler(function ($no, $err, $file, $line)
{
    // do whatever you want to if an error of type E_WARNING occurs
}, E_WARNING);

Upvotes: 0

Related Questions