Hi all, been dipping my toe into OOP and am getting on OK, but I'm hitting a bit of a wall with a current project.
classes:
db (a PDO extended class)
User
Timetable
The db is just a few shorthand ways of running PDO
The User is just for handling the current user's details, e.g. profile etc.
The Timetable is for showing the user's current timetable (and a few other things)
I've currently got this thing going on in my page:
include("includes/config.php");
include("class/class.DB.php");
include("class/class.User.php");
include("class/class.Timetable.php");
$db = new db($config['db']);
$u = new User($db);
$t = new Timetable($db,$u);
where I pass the db object to both user and timetable and pass the user object to the timetable. Is this the best way to do things?
In my timetable constructor I have this:
$this->db = (object) $db;
$this->user = (object) $u;
But if I want to use the user's 'detail' property in the timetable class, I have to make $detail public - protected won't work. Does protected only work for child classes? If so, must I make these public? Don't like the idea of that.
in user class:
public $detail;
to use it thus, in timetable (example):
$where = ($this->user->detail['rights'] > 7) ? "" : " WHERE s.staff_id = {$this->user->detail['staff_id']}";
I'm still a little off with abstract classes and interfaces, so apologies if I need to do something with those - I'm still learning.