Trying to get my head around inheritance and visibility
I have a parent core class which is generic. I have db, query methods etc. Things which i think could be abstract. Is it normal practice to pass in an object from another class say an error handling class as an argument. I klnow you can extend a class but i just need this errors class visible to other classes
$errors = new errors;
$core = new core($errors);
Is it worth separating this errors method into its own class?
Generally the only object I pass into child classes would be a register object, holding the current important application information, such as the database, any errors and the current request etc.
So for example:
$WebApplication = new WebApplication();
$WebApplication->setRequest($request);
$WebApplication->setDatabase($database);
$WebApplication->setErrors($errors);
$Core = new Core($WebApplication);
The core object then instantiates other objects by passing the webapplication variable down with it. Each child class can then use the database, error object and access the uri without any problems.
It’s also useful for testing. You can create a dummy webapplication object and pass in dummy post variables, requests and database objects etc to see how your application handles different circumstances.