函数头与包含头php?-正反两面

函数头与包含头php?-正反两面,php,performance,caching,Php,Performance,Caching,我主要是寻找性能,网站缓存,易于键入和安全-正面和负面 拆分文件并将其作为包含项扔进,这似乎是一个共同的偏好 <?php include('header.php');//and whatever includes inside include('footer.php');//and whatever includes inside ?> VS 将它们转换为函数并在一个文件中调用,在该文件中,您可以检查值并在两个函数(如多样式选项)之间共享它们 <?php includ

我主要是寻找性能,网站缓存,易于键入和安全-正面和负面

拆分文件并将其作为包含项扔进,这似乎是一个共同的偏好

<?php
include('header.php');//and whatever includes inside 
include('footer.php');//and whatever includes inside 
?>

VS

将它们转换为函数并在一个文件中调用,在该文件中,您可以检查值并在两个函数(如多样式选项)之间共享它们

<?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
}
?>

这个坏了

尽管使用页眉和页脚(无论是显式调用还是隐式调用)几乎不可避免地会导致格式错误的HTML片段,但当您显式调用它(作为函数/方法)时,至少可以在同一个文件中定义这两个片段


性能不会有显著差异。

性能:可能会有细微的差异,但不会有太大的差异,以至于您无法检测到。另外:基准测试它。缓存:没有任何影响。打字方便:自己决定。保安:???“安全性”是什么?只是一个旁注,当变量为小写时,您不能访问cookies/会话。它必须是
$\u COOKIE
/
$\u会话
include('header.php');//and whatever includes inside  
include('footer.php');//and whatever includes inside