What would you advise me to use performance wise between the following
A)
function db(){ return new mysqli('localhost','user','pass','db'); }
//global scope
$db = db();
function foo(){
//function scope
$db = db();
[...]
}
B)
//global scope
$db = new mysqli('localhost','user','pass','db');
function bar(){
//function scope
global $db
[...]
}
At the moment I'm using method A but I'm aware there is a overhead in calling a function and db() is called in most functions, so I was wondering.