我主要寻找性能,网站缓存,易于打字和安全性 - 优点和缺点
拆分文件并将它们作为包含放入,似乎是共享的偏好
<?php
include('header.php');//and whatever includes inside
include('footer.php');//and whatever includes inside
?>
与
将它们制作成函数并在一个文件中调用它们,您可以在其中检查值并在两个函数(如多样式选择)之间共享它们
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/more-functions.php';
if(isset($_cookie['style']) || isset($_session['style'])){
if(isset($_cookie['style'])){$style = $_cookie['style']}else{$style = $_session['style']}
}
function siteheader($style){
if(!isset($style)){$style = 'default';}
print ('<http>');//insert rest of header
}
function sitefooter($style){
if(!isset($style)){$style = 'default';}
print ('</http>');//insert rest of footer
}
?>
include('header.php');//and whatever includes inside
include('footer.php');//and whatever includes inside
这会破坏 PSR-1。
虽然使用页眉和页脚(无论是显式调用还是隐式调用)几乎不可避免地会导致格式不正确的 HTML 片段,但当您显式调用它(作为函数/方法)时,您至少可以在同一个文件中定义两个片段。
性能不会有显著差异。