I have a class that needs access to two other classes. Signin needs access to Post, and Signin needs access to Database. How do I do this?
I had previously made the inheritance chain linear, but this seems to confuse people as a Post is not a Database.
PHP does not have multiple inheritance (as I think you understand already). If you cannot make a linear inheritance chain, another option is create and implement an interface:
However, that doesn’t seem to fit your situation either.
For your needs, it my be appropriate to pass the
Databaseobject and thePostobjects into theSigninobject via dependency injection. After all, isSigninreally an extension ofDatabase? Is it an extension ofPost(maybe). Dependency injection may be a more appropriate OO methodology here.How it is used: