My friend adviced me: Jesus, man! Don't use GLOBALs. It makes your software slow.
This is my way:
// Database class
class DB extends mysqli { ... }
// create Database object
$db = new DB(...)
// My class
class A {
function foo(){
global $db; ## PROBLEM IS HERE
$db->get_all(...);
}
}
Is there any way to use $db object without make it GLOBAL? or should I stop to listen to my friend?
Sure. Just create a property for your
$dbobject and pass it into objectA, via the constructor (or create a setter method):Is this what you mean?