Bottom line - do not create classes containing only static functions. This is not OOP, it's just your old procedural code disguised as oop
If you execute functions statically, there is no $ this, since there is no object. You will also become the static variable private $db and use it as self::$db .
However, I would recommend abandoning this template and writing something like:
class Foobar { protected $_connection = null; public function __construct( DBConnect $db ) { $this->_connection = $db; } public function some_function() { $db = $this->_connection;
And you use this class as follows:
$db = new DBConnection( ); $stuff = new FooBar( $db ); $stuff->some_function(); $blah = new DifferentClass( $db );
This way you use the same connection with all classes that require it. And now the FooBar class FooBar not responsible for establishing a connection or should know your connection details.
source share