A couple of the options are:
$connection = {my db connection/object}; function PassedIn($connection) { ... } function PassedByReference(&$connection) { ... } function UsingGlobal() { global $connection; ... }
So, passed in, passed by reference, or using global. I’m thinking in functions that are only used within 1 project that will only have 1 database connection. If there are multiple connections, the definitely passed in or passed by reference.
I’m thining passed by reference is not needed when you are in PHP5 using an object, so then passed in or using global are the 2 possibilities.
The reason I’m asking is because I’m getting tired of always putting in $connection into my function parameters.
I use a Singleton ResourceManager class to handle stuff like DB connections and config settings through a whole app:
And then in functions / objects / where ever:
I use it to store messages, error messages and warnings, as well as global variables. There’s an interesting question here on when to actually use this type of class.