I have a little strange issue with my php 7.4... I imported a website from another place on a new ubuntu server. In this wordpress website I have a plugin where I have a php file containing this function (there are omissions because they are private):
function insert_registration() 
{
    
    if ( $this->validate_state === FALSE ) 
    {
    
        echo $this->validate_state;
        $this->title_message = __('XXXXXXXXXXXX!', 'XXXXXXX');
        $this->error_message = __('XXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXX') . ' ';
        $this->error_message .= $this->error_reason;
        ?>
            <script type="text/javascript">new $.Zebra_Dialog('<?php echo $this->error_message; ?>', { 'custom_class': 'XXXXXXXX', 'title' : '<?php echo $this->title_message; ?>' });</script>
        <?php
        
        
    } 
    else  // <-------- the ELSE where the error is complaining about
    {
    
        $asd = $this->wpdb->insert(
            'XXXXXXX',
            array(
                'XXXXXXX' => $this->var1,
                'XXXXXXX' => $this->var2,
                'XXXXXXX' => $this->var3,
                'XXXXXXX' => $this->var4,
                'XXXXXXX' => (!$this->var5 ? '': $this->var5),
                'XXXXXXX' => MD5($this->var6),
                'XXXXXXX' => current_time('mysql', 1)
            ),
            array('%s', '%s', '%s', '%s', '%s', '%s', '%s')
        );
        
        $asd2 = $this->wpdb->insert_id;             
        
        if ( $asd == 1 ) 
        {
            
            if ( isset($this->var7) ) 
            {
                $varvar7 = $this->wpdb->get_var('SELECT XXXXXXXXX FROM XXXXXXXX WHERE XXXXXXXX = "' . $this->var7 . '" ' );
            }
            $new_var7 = $this->wpdb->get_var('SELECT CAST(LPAD(IFNULL(MAX(CAST(XXXXXXXXXXX AS UNSIGNED)), 000000)+1, 6, "0") AS CHAR(6)) AS "col1" FROM XXXXXXXXXXXXX');
            
            $new_var = $this->wpdb->insert(
                'XXXXXXXX',
                array(
                    'XXXXXX' => $this->var1, 
                    'XXXXXX' => $this->var8,
                    'XXXXXX' => $this->var9,
                    'XXXXXX' => $new_var7,
                    'XXXXXX' => $asd,
                    'XXXXXX' => $new_var7,
                    'XXXXXX' =>  $this->var10,
                    'XXXXXX' => 1
                ),
                array('%s', '%s', '%s', '%d', '%d', '%s', '%s', '%d')
            );
            $var7 = $this->wpdb->insert(
                    'XXXXXXXXX',
                    array(
                        'XXXXXXXXX' => $new_var7
                    ),
                    array('%d')
            );
            if ( !($new_var7 == 1) ) 
            {
                
                $this->var9 = __('XXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXx');
                $this->var10 = __('XXXXXXXXXXXXXXXXXXxx', 'XXXXXXXXXXXXXXXXXx');
                ?>
                    <script type="text/javascript">new $.Zebra_Dialog("<?php echo $this->var9; ?>", { "custom_class": "xxxxxxxxxx", "title" : "<?php echo $this->var10; ?>"});</script>
                <?php   
                
                
            } else {                
                                        
                // message user udpated
                $this->var9 = __('XXXXXXXXXXXXXXXXXXXXXx', 'XXXXXXXXXXXXXXXX');
                $this->var10 = __('XXXXXXXXXXXXXXXXXXXXX','XXXXXXXXXXXXXXXXX');
                $session_lang = pll_current_language();
                $browser_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
                $this->url_redirect = "XXX.XXX.XXX.XXX";
                if ($session_lang != $browser_lang) 
                {
                    $this->url_redirect .= $session_lang . "/";
                }
                
                
                ?>
                    <script type="text/javascript">new $.Zebra_Dialog('<?php echo $this->var9; ?>', { 'custom_class': 'XXXXXXXXXXXXXx', 'title' : '<?php echo $this->var10; ?>', 'onClose' : function(caption) { window.location='<?php echo $this->url_redirect; ?>'; } }); </script>
                <?php
                
                $message_html_template =  '<h1 style="font-family: Calibri"><center>XXXXXXXXXXXXXXXXXX</center><h1> <hr>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX') . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXX ', 'XXXXXXXXXXXXXXX') . $new_var7 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXX: ', 'XXXXXXXXXXXXXx') . $this->asd1 . ' - ' . $this->asd2 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXX: ', 'XXXXXXXXXXXXX') . $this->asd3 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXx ', 'XXXXXXXXXXX') . $this->asd4 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXxx: ', 'XXXXXXXXXXXXXX') . $this->asd5 . '</p></div>';
                $message_html_template .= '<hr><div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXX</center></p></div>';
                                        
                $to = $this->to;
                $subject = __('XXXXXXXXXXXXXx', 'XXXXXXXXXXXxxx');
                $message = $message_html_template;
                $headers = 'From: XXXXXXXXXXXXX <XXXXXXXXXXXXXX>' . "\r\n";
                
                add_filter('wp_mail_content_type', function( $content_type ) { return 'text/html'; });
                wp_mail( $to, $subject, $message, $headers );
                
                $message_html_template =  '<h1 style="font-family: Calibri"><center>XXXXXXXXXXXXXXXXXX</center><h1> <hr>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX') . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXXX ', 'XXXXXXXXXXXXXXX') . $new_var7 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXX: ', 'XXXXXXXXXXXXXx') . $this->asd1 . ' - ' . $this->asd2 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXXXX: ', 'XXXXXXXXXXXXX') . $this->asd3 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXx ', 'XXXXXXXXXXX') . $this->asd4 . '</p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p>' . __('XXXXXXXXXXXxx: ', 'XXXXXXXXXXXXXX') . $this->asd5 . '</p></div>';
                $message_html_template .= '<hr><div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXXXXX</center></p></div>';
                $message_html_template .= '<div style="font-family: Calibri; font-size: 0.6em"><p><center>XXXXXXXXXXXXXXXXXX</center></p></div>';
                
                $to = get_bloginfo('admin_email');
                $subject = 'XXXXXXXXXXXXXXXXXXXX';
                $message = $message_html_template;
                $headers = 'From: XXXXXXXXXX <XXXXXXXXXX>' . "\r\n";
                
                add_filter('wp_mail_content_type', function( $content_type ) { return 'text/html'; });                          
                wp_mail( $to, $subject, $message, $headers );
                                        
            }
            
        } else {
            ?>
                <script type="text/javascript">new $.Zebra_Dialog('<?php echo $new_var->get_error_message(); ?>');</script>
            <?php                   
        }
    
    }
}
I checked all the indentations of the whole PHP file and they looks correct but the website goes down with an error and reading the error.log file I see :
[Tue May 03 11:08:11.334843 2022] [php7:error] [pid 3075] [client XXX.XXX.XXX.XXX:59496] PHP Parse error: syntax error, unexpected 'else' (T_ELSE), expecting function (T_FUNCTION) or const (T_CONST) in
but as I said before all indentations are correct... could be maybe related to the presence of mixed HTML and PHP code? like in the else:
... else { ?> <script type="text/javascript">new $.Zebra_Dialog('<?php echo $new_var->get_error_message(); ?>');</script> <?php }
where maybe php doesn't like it? In the previous server it didn't give any errors,... maybe some php.ini misconfiguration?
thanks in advance to all! Cheers!!
EDIT: Removed all code then re-added step-by-step , I figured this piece of code:
function registration_template_form() 
{
    $this->var1 = __('XXXX', 'XXXX');
    $this->var2 = __('XXXXX', 'XXXXXX');
    $this->var3 = __('XXXXX', 'XXXXX');
    
    ?>  
    <script type="text/javascript">             
    </script>           
    <div class="popup_canvas_container">
    </div>
    <?
    
}
breaks the website and throwns the error even if different message than earlier but so it looks like it is related about mixing html with php; in fact removing the html part in the function then it works.
