1

I have a class (crypt) that helps me encrypt, decrypt. Then, another class (sess) for session starting, restricting and protecting pages. Then, another class (db) for storing session variables, sometimes by encryption like login time, logout time, server referrer etc. Now, with all this, how do I gain access to the three classes different functions in each of those classes as I can only extend one? The Crypt class is just helping to encrypt,I need it in almost every other class.furthermore, I know this questiön has been so answered that its becoming rhetoric but my main enquiry is the 'safest' method.

Akintunde
  • 11
  • 2
  • possible duplicate of [Multiple Inheritance in PHP](http://stackoverflow.com/questions/90982/multiple-inheritance-in-php) – Marc B Aug 12 '13 at 15:20
  • 3
    Which classes does __really__ need to be inherited from another? "Crypt" sounds like a static helper-class, for instance. Possiple duplicate of http://stackoverflow.com/questions/90982/multiple-inheritance-in-php – davidkonrad Aug 12 '13 at 15:22

2 Answers2

0

the way i do it is with a model class, which is used to call references to database, session and crypt classes, does the method calls, gets values back, and processes business logic, then returns the data to view.

simply put, your website should be:

root
-assets
--css
--img
--js
-modules
--home_page
--register_page
--login_page
-includes
--session_class
--crypt_class
--database_class
index

go go go

Kirka121
  • 505
  • 4
  • 13
  • Nice directory structure, but doesn't really explain how to access one class/object from within another – Mark Baker Aug 12 '13 at 15:32
  • your modules use "include("/includes/database_cklass.php"); – Kirka121 Aug 12 '13 at 15:34
  • then in your modules you call Database->add or whatever method u have. if the class isnt static, you will have to initialize it first, by doing Database database = new Database(); and then doing the database->add call – Kirka121 Aug 12 '13 at 15:35
  • including a file doesn't help the code logic if a method in the session_class object needs to access a method in the crypt_class – Mark Baker Aug 12 '13 at 15:35
0

I've solved it.I used-CLASS db Extends Crypt,then CLASS Sess Extends db.The funny part is db functiöns wön't work in Sess Class unless I use a :New Db;then $db->mylog() but for the Crypt class works through Parent::encrypt().funny!its like it jumped a step.Probably because I used Parent::encrypt() in the __construct function of Db.Its rough,but I know I didn't break things.

Akintunde
  • 11
  • 2