Is there a substantial impact in performance (both in the browser and on the server) by exiting and entering the PHP render engine? Example:
<p>Lorem ipsum..</p>
<?php
myPHPfunction();
?>
<开发者_高级运维;p>more html</p>
<?php
anotherPHPfunction();
?>
If this is a big impact in terms of performance, how can I bundle all of the PHP up together, especially if the majority of my pages are static HTML?
In terms of performance, there really isn't a downside of doing this. When you use these echo statements, PHP is building an internal ouput buffer that will eventually get flushed to the browser once the page is done executing. There are ways around this, such as ob_flush
.
However in terms of separation of concern and overall software design, it is bad to put business logic(NOT view logic as Brenton pointed out below) with your views. Your code becomes harder to maintain if you have this type of setup.
精彩评论