Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close curly brackets in PHP [closed]

Is it ok in PHP to close out curly bracket as follows?

<?php function myfunction() { ?>

   // stuff

<?php } ?>                 
<?php 

// more stuff

I just discovered that this breaks my Wordpress site, however if I close out the bracket like this:

<?php function myfunction() { ?>

   // stuff

<?php }                  

// more stuff

No problems are caused.

It's been a confusing afternoon! Any help much appreciated.

like image 614
user18577 Avatar asked Oct 26 '12 14:10

user18577


1 Answers

It is usually a bad idea to do:

?>
<?php

That adds output to the page, and prevents one from adding any headers, which may cause error if any code tries to add a header.

Whereas:

//nothing

Does not.

like image 157
Naftali Avatar answered Sep 28 '22 16:09

Naftali