Jump to content

Tip: Add PHP warnings to ProcessWire logs


da²
 Share

Recommended Posts

Hello,

Recently, while debugging something, I found I had unsolved PHP warnings. Because I'm using Twig, PHP warnings are not displayed at top of page.
Not being aware that we have warnings in our code is not acceptable. ?‍♂️

So I added this code in site/init.php:

set_error_handler(
    function (int $errorNumber, string $message, string $file, int $lineNumber): bool {

        wire()->log->save('php-warnings', "Fichier \"$file\", ligne $lineNumber => $message");

        // Return true so PHP won't process these warnings and display them at top of page.
        return true;
    },
    E_WARNING);

The log:

image.thumb.png.64d04702c759a7065aeba83a2abfb47b.png

 

Do you think it should be integrated in PW base installation, like errors and exceptions?

If you have another way of managing this warnings, don't hesitate to share. ?

 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...