admin管理员组

文章数量:1122832

After update to PHP8 I get errors:

PHP Parse error: Unmatched '}' in /public_html/wp-content/themes/theme/functions/a_critical_css.php on line 44

The file looks like:

<?php   
if ( ! defined( 'ABSPATH' ) ) { 
  exit; // Exit if accessed directly.
}

function add_my_critical_css(){ ?>

  <style>
    body {
      margin: 0;
      font-family: Arial, sans-serif;
      color: #717a8f;
      padding-top: 44px;
      line-height: 1.3;
      background: #fff;
      -webkit-tap-highlight-color:rgba(255, 255, 255, 0.1);
    }
  </style>
<?php
} //this is line 44
add_action('my_critical_css','add_my_critical_css');

The problem is that if I downgrade PHP, website works perfect. When I upgrade... I get critical Wordpress error.

Could somone help me how to solve the problem?

Thank you in advance.

After update to PHP8 I get errors:

PHP Parse error: Unmatched '}' in /public_html/wp-content/themes/theme/functions/a_critical_css.php on line 44

The file looks like:

<?php   
if ( ! defined( 'ABSPATH' ) ) { 
  exit; // Exit if accessed directly.
}

function add_my_critical_css(){ ?>

  <style>
    body {
      margin: 0;
      font-family: Arial, sans-serif;
      color: #717a8f;
      padding-top: 44px;
      line-height: 1.3;
      background: #fff;
      -webkit-tap-highlight-color:rgba(255, 255, 255, 0.1);
    }
  </style>
<?php
} //this is line 44
add_action('my_critical_css','add_my_critical_css');

The problem is that if I downgrade PHP, website works perfect. When I upgrade... I get critical Wordpress error.

Could somone help me how to solve the problem?

Thank you in advance.

Share Improve this question edited Aug 4, 2023 at 1:35 YourManDan 4342 silver badges12 bronze badges asked Aug 3, 2023 at 19:15 TereskaTereska 313 bronze badges 2
  • 1 Copy and pasted your code into a WordPress install on PHP 8, and did not receive any error. Only recommendation I can make is to cleanup your code to be more readable: putting PHP tags on their own lines, indenting properly, etc. – Caleb Commented Aug 3, 2023 at 19:36
  • Is this the entire file, or just a section of it? There's nothing wrong with this code as far as I can see, but if there's more to the file there may be an issue with earlier parts of it. – YourManDan Commented Aug 3, 2023 at 20:00
Add a comment  | 

1 Answer 1

Reset to default 0

I'm having the same exact issue. Same message in PHP 8 but not in PHP 7.4. The code is properly indented, ect. and can't find a single issue.

本文标签: fatal errorWhy PHP Parse unmachet after update to PHP8