Safe alternatives to PHP Globals (Good Coding Practices)

后端 未结 6 1226
渐次进展
渐次进展 2020-12-03 04:03

For years I have used global $var,$var2,...,$varn for methods in my application. I\'ve used them for two main implementations:

Getting an already set cl

6条回答
  •  臣服心动
    2020-12-03 04:30

    function showPage(&$output, $db = null){
         $db = is_null( $db )  ? new Database() : $db;
         $output['header']['title'] = $db->getConfig( 'siteTitle' );
         require( 'myHTMLPage.html' );
         exit();
    }
    

    and

    $output['header']['log_out'] = "Log Out";
    showPage($output);
    
     $db =new Database();
    showPage($output,$db);
    

提交回复
热议问题