Syntax error closing brace after opening php tag

I am having problems with a function that looks something like this:

<?php 
function my_function() {

    if(!empty($variable)) {
        //Do some stuff
    }
    else {
        ?>show a message<?php 
    }
}
?>

The problem is that I get a parsing error:

Parse error: syntax error, unexpected '} in /www/bla/bla/bla.php on line 8

I know that I am not missing or have no extra '}' bracket because the code works very well on my local server, and I ran the validator to make sure the syntax is correct, however, when I transfer the code to the online server, I get an error.

I believe this is due to the installation of php, which does not support closing and reopening php tags between the condition, but I'm not sure how I would fix it.

, echo 'message'; , , script , , , .

.

+3
2

, , PHP 5.2.14.

, , ?:

?>show a message<?php

, , , <?, SHORT_OPEN_TAG php.ini, :

?>show a message<?
+3

. :

<?php } ?> 

, , , -, :

<?php 
  //
  }
?>
0

Source: https://habr.com/ru/post/1767118/


All Articles