Hi, I was wondering about when it is best practice to extend a class or best to create an object of one class within a class.
Anyone have any rules you go by?
For example:
myDatabaseClass extends mysqli{} makes sence because there’s no confusion of responsibility and it allows me to use all the mysqli functionality within my class.
But,
myPaginateClass extends myDatabaseClass{} would allow me to use myDatabaseClass functionality but would also give myPaginateClass access to mysqli.
For security, logic flow, separation of responsibility would it be better to include myDatabaseClass with a “require_once()” in the myPaginateClass and create a database object for use with the paginate functions?
Or would it be best to keep the classes totally separate, create objects of both in the main script, and use vars or arrays to pass info from one to the other?
It gets more complicated if I add yet another class for validation and data sanitizing so I want to get into the best practice and want to know how you would do it and why.
Thanks