I have a class that relies on several other classes present. So I pass these other classes through my build function, and it all works great. However, when I pass in a class that requires a parameter for its own build function, I get the error message "Missing argument 1 for mysql :: __ construct () ...". What is the best method for passing objects through a class with the required parameters?
If you see any potential flaws in this design, please let me know. I am new to Object Orientation and, as a result, still participate.
An example of what I have and does not work:
class mysql{ function __construct($memcache){ // Construct the object } } class company{ function __construct($databases,$connections,$mysql,$facebook){ // Construct the object // Make the MySQL class available to all the methods $this->mysql = $mysql; } } // Initialize the objects (Company, MySQL, Memcache and Facebook) $memcache = new memcache; $facebook = new Facebook($facebook_config); $mysql = new mysql($memcache); $company = new company($_DATABASES,$_CONNECTIONS,$mysql,$facebook);
SOLVED UDPATE
The above code is actually correct, the problem was that I called __construct() at the end of one of my methods, and I forgot to pass the $ memcache parameter
source share