0

I'm receiving the following error:

Parse error: syntax error, unexpected '}', expecting end of file in /blah/blah/Edit.php on LINE_WITH_COMMENT

for this code inside my Edit.php view file.

<? $categories = $this->config->loader->getCategories(); 
   foreach($categories as $category) { ?>
   <?  $selected = $this->obj->category==$category ? 'selected' : ''; ?> 
       <option value="<?=$category?>" <?=$selected?>><?=$category?></option>

   <?php } ?>  //ERROR IS HERE

But if I change <?php to the short open tag <?, the error goes away, and my script works as expected.

It works on my server with hostgator with <?php but on my local machine it's only working with <? and giving the fatal error if I have <?php.

From phpinfo() on the local machine: PHP Version 7.2.17-0ubuntu0.19.04.1

I've changed <?php to <? for now, but how can I fix this? I prefer not to use short open tags.

Reed
  • 14,703
  • 8
  • 66
  • 110

1 Answers1

0

It actually turned out my short_open_tags were set to Off in my php.ini.

So I went to /etc/php/7.2/apache2/ did nano php.ini, found the setting by searching short_open and changed short_open_tags = Off to short_open_tags = On... then I decided to turn it back off because... I've read you're supposed to keep it off. Then I changed my other <?s to <?php.

The problem was that I WAS using short open tags <? for parts of the code, and it was not getting evaluated - rather it was output. And I didn't see it was output because I was looking at the rendered page, rather than the source for the page, and i was only seeing confusing problems in the rendered page

Reed
  • 14,703
  • 8
  • 66
  • 110