0

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.

Edited by diafol: n/a

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
1

The way you describe it, it sounds like the timetable should be a part of the user.

And yes, protected can be accessed only by ancestors and descendants.

0
The way you describe it, it sounds like the timetable should be a part of the user.

And yes, protected can be accessed only by ancestors and descendants.

Ok - protected now makes sense.
When you say timetable should be part of user, do you mean as a property?
Thinking about it, that does sound sensible.
Thanks pritaeas.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.