SOLVED: PHP Notice when triggering 404 page on php 8+

Browser: Chrome 110
OS: macOS / Windows / Linux / etc.

Hi all,
When on php 8, 8.1 everytime the 404 page is triggered I get this error log:
Attempt to read property “post_title” on null in public_html/wp-content/themes/bricks/includes/conditions.php on line 412

If I switch to php 7.4 there is no error.

Tested on Bricks 1.7.3, 1.7.2, 1.71…

Found the problem!
It was a condition in the global Footer template:
Had a section above the footer that I wanted to show only on specific pages…
If I remove the condition , there is no more error.
Is this the right way of achieving this condition?
@timmse

Hi gokki,
Thanks so much for your report!

First of all, it is a PHP notice, not an error.
The reason why the notice is issued is that $post->post_title is not available in the 404 template, and PHP>7.x treats this differently.

You can work around this problem by not using the post title in the condition, but e.g. the post_url and the WordPress functions is_front_page() and is_404() (if you want to show the section on the 404 page/template too).

Best regards,
timmse

2 Likes

Yes you are right, its a PHP notice not an error :slight_smile:
Thank you for the quick response and solution @timmse!