flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.6k stars 407 forks source link

display_errors does not work with flight #483

Closed louishot closed 5 months ago

louishot commented 1 year ago

I have configured display_errors = Off in php.ini but flight still output details of 500 Internal Server Error

Directive Local Value Master Value
allow_url_fopen On On
allow_url_include Off Off
arg_separator.input & &
arg_separator.output & &
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file no value no value
browscap no value no value
default_charset UTF-8 UTF-8
default_mimetype text/html text/html
disable_classes no value no value
disable_functions no value no value
display_errors Off Off
display_startup_errors Off Off
<h1>500 Internal Server Error</h1><h3>Argument 1 passed to flight\util\Collection::setData() must be of the type array, string given, called in /home/www/api/html/vendor/mikecao/flight/flight/net/Request.php on line 194 (0)</h3><pre>#0 /home/www/api/html/vendor/mikecao/flight/flight/net/Request.php(194): flight\util\Collection->setData()
#1 /home/www/api/html/vendor/mikecao/flight/flight/net/Request.php(158): flight\net\Request->init()
#2 /home/www/api/html/vendor/mikecao/flight/flight/core/Loader.php(125): flight\net\Request->__construct()
#3 /home/www/api/html/vendor/mikecao/flight/flight/core/Loader.php(81): flight\core\Loader->newInstance()
#4 /home/www/api/html/vendor/mikecao/flight/flight/Engine.php(101): flight\core\Loader->load()
#5 /home/www/api/html/vendor/mikecao/flight/flight/Engine.php(314): flight\Engine->__call()
#6 /home/www/api/html/vendor/mikecao/flight/flight/core/Dispatcher.php(198): flight\Engine->_start()
#7 /home/www/api/html/vendor/mikecao/flight/flight/core/Dispatcher.php(144): flight\core\Dispatcher::invokeMethod()
#8 /home/www/api/html/vendor/mikecao/flight/flight/core/Dispatcher.php(49): flight\core\Dispatcher::execute()
#9 /home/www/api/html/vendor/mikecao/flight/flight/Engine.php(92): flight\core\Dispatcher->run()
#10 /home/www/api/html/vendor/mikecao/flight/flight/core/Dispatcher.php(198): flight\Engine->__call()
#11 /home/www/api/html/vendor/mikecao/flight/flight/Flight.php(77): flight\core\Dispatcher::invokeMethod()
#12 /home/www/api/html/index.php(83): Flight::__callStatic()
#13 {main}</pre>
mjisoton commented 1 year ago

What about the error_reporting directive? It looks like FlightPHP checks if the error level is within the error_reporting directive with a bitwise operation, and then calls the handler function for Exceptions:

public function handleError($errno, $errstr, $errfile, $errline) {
  if ($errno & error_reporting()) {
     throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
  }
}

So, if you really don't want any kind of error to be shown, you probably should set error_reporting=0 in your php.ini. Not sure though.

krmu commented 6 months ago

+1 Tested, specially when you try to render a PHP file (Flight::render). It just wont load, but it has error inside of it. If file has error outside of the framework, it shows errors correctly but render function gives blank page.

n0nag0n commented 6 months ago

Good to know, thanks for verifying this!

Now that unit testing coverage is at 100%, finding stuff like this and accepting pull requests will be much easier.

On Wed, Jan 3, 2024 at 1:54 PM Kristaps @.***> wrote:

+1 Tested, specially when you try to render a PHP file (Flight::render). It just wont load, but it has error inside of it. If file has error outside of the framework, it shows errors correctly but render function gives blank page.

— Reply to this email directly, view it on GitHub https://github.com/flightphp/core/issues/483#issuecomment-1875959090, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARW5LZMKGJERYGULGDXJE3YMXARVAVCNFSM6AAAAAAVWJN3CCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZVHE2TSMBZGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

krmu commented 5 months ago

Error reporting works when you use Flight::Render for all the files that you have. For me, the fix was to use the renderer for all files that should be used. I will close this for now. If someone still has an issue with this, please create a new issue ticket.