Several blocks vs single one (semantics and functionality)

What I keep seeing is something like

<?php $page_title = ""; ?>
<?php include_once("inc/header.php"); /* Include Header */ ?>


$page_title = ""; 
include_once("inc/header.php"); /* Include Header */ 

I assume there is no difference in functionality (not sure however), but which way is more semantic / correct does it matter if you declare all your PHP in several PHP blocks or a single one? Is performance affected in any way?


This is a major reason why doing your PHP inline is going out of style. There’s no performance hit that I know of. All <?php ?> does is tell the interpreter that this is to be processed by PHP so your first code block is saying

Stop parsing PHP
Start Parsing PHP

I would imagine there’s some miniscule hit somewhere if you’re trying to wring every last ounce of efficiency out but I consider it to be insignificant. It’s important to userstand that if you’re using opcode cache (and you should) then the only hit is on the parsing side. Repeated execution of cache will have 0 effect here.

Readability, however, really does demand your code be as compact as possible. Remember, someone may come behind you and work on this code. Having two blocks where only one is needed is inefficient.