0

Good day!

I am trying to change the PHP version from 7.4 to 8.0 on my Wordpress but it breaks. With PHP debug I see that the error is located in my child theme (all my plugins are deactivated):

Unmatched ')' on line 1115

I run the code on php tester and I don't see any mistake... And I doubt unmatched parenthesis can be the real error, as it should show also in previous PHP versions. Does anybody have a hint to guide me? Thanks!

This is the source code of the function, in case it's useful

function getTermsOfPost($postId){
    $metaStr="";
    $term_list = wp_get_post_terms($postId, 'post_tag', array("fields" => "all"));
    $i = 1;
    $arr = array(
        "elem1", "elem2", "elem3"
    );
    foreach($term_list as $termSingle){
        if(in_array($termSingle->name, $arr)){
            if($i == 1) {
                $metaStr = $termSingle->name;
            } else {
                $metaStr .= ",<br/>".$termSingle->name;
            }

            $i++;
        }
    } //line 1115
    return $metaStr;
}
Fabbio
  • 343
  • 2
  • 16
  • Nobody can give you a hint on something abstract… You should provide in your question the related function code (or block code) that is making an issue. – LoicTheAztec Aug 24 '23 at 08:20
  • Hi @LoicTheAztec! Probably you're right, but the issue is not my code, but the upgrade from 7.4 to 8.0 I hope somebody knows what changed to generate such error. But I will add the function code, thanks. – Fabbio Aug 24 '23 at 08:24
  • It can be so many things, that nobody can really give you any hint actually, with the provided details in your question. – LoicTheAztec Aug 24 '23 at 08:49
  • that character ")" isn't in (or near) the line you identify as 1115. Do you mean "}" or is the error in another script? Copying the full error you get would clarify this. – timchessish Aug 24 '23 at 08:57
  • 1
    Could be an "invisible" character anywhere before this position, something that the 7.4 parser was fine with, but now in 8.0 it isn't any more - and editor with the option to show all characters, even not printable ones, could help with the hunt. Could also be that short open tags got used _somewhere_, but the corresponding config option to enable them was only set in your 7.4, but not under 8 any more. – CBroe Aug 24 '23 at 09:23

1 Answers1

0

After four hours of darkness, I finally find out the whole mess was caused by the short tags being disabled in the new version of PHP. There was some javascript mixed with php and this created the completely wrong error messages. Thanks for your support, if anybody else is struggling these links helped me:

Parse error: Syntax error, unexpected end of file in my PHP code

https://www.php.net/manual/en/language.basic-syntax.phptags.php

Fabbio
  • 343
  • 2
  • 16