bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

Error messages missing where the actual error occurs #1255

Closed hessodreamy closed 2 years ago

hessodreamy commented 2 years ago

Just upgraded to php 8.1.5 and fat free 3.8. I'm expecting some errors but the error logs generated by fat free are not helpful in tracking down the error. The logs generated are:

[Mon May 16 14:59:13.565941 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/vendor/bcosca/fatfree-core/base.php:2375] Base->error()
[Mon May 16 14:59:13.566939 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/vendor/bcosca/fatfree-core/base.php:2233] Base->{closure}()
[Mon May 16 14:59:13.566939 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/vendor/bcosca/fatfree-core/base.php:2233] require('C:\\vhosts\\vendor\\bcosca\\fatfree-core\\base.php')
[Mon May 16 14:59:13.566939 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/core/controller/Controller.php:80] Base->autoload()
[Mon May 16 14:59:13.566939 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/vendor/bcosca/fatfree-core/base.php:1934] ReflectionClass->newInstanceArgs()
[Mon May 16 14:59:13.566939 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/vendor/bcosca/fatfree-core/base.php:1955] Base->grab()
[Mon May 16 14:59:13.566939 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/vendor/bcosca/fatfree-core/base.php:1783] Base->call()
[Mon May 16 14:59:13.566939 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:51938] [C:/vhosts/mydomain.com/web/index.php:37] Base->run()
Mon, 16 May 2022 15:59:13 +0200 [127.0.0.1] Optional parameter $useNamesAsHeaders declared before required parameter $fileHandle is implicitly treated as a required parameter

Which totally misses any mention that the error occurs in C:/vhosts/core/lib/helper/Report.php line 83. I've found in the past that fat free error logs are missing important information so it could be I'm missing something. Surely it would be better to include this?

Easily achieved by tweaking base.php in a few places:

line 2375 change $this->error(500,$text,NULL,$level); to $this->error(500,$text,NULL,$level, $file, $line);

line 1355 change function error($code,$text='',array $trace=NULL,$level=0) { to function error($code,$text='',array $trace=NULL,$level=0, $file=null, $line=null) { (or just updating all places using this function to use these extra args)

line 1370 from error_log($text); to error_log($text . ($file? $file . ':' . $line : ''));

Now the main log entry reads: [Mon May 16 15:46:17.745832 2022] [php:notice] [pid 14084:tid 1808] [client 127.0.0.1:52272] Optional parameter $useNamesAsHeaders declared before required parameter $fileHandle is implicitly treated as a required parameter in E:\\vhosts\\core\\lib\\DbHelper.php line 232

ikkez commented 2 years ago

fixed in https://github.com/bcosca/fatfree-core/commit/59a3d45f24b061f9b2ce813cd1146f0cfcc6e3cc