Twister1004 Posted January 13, 2012 Share Posted January 13, 2012 HI everyone! So basically I have this class called Login and another class classed Reports. They both extend a main class called OOP. I'm trying to get classes now and in the future, when I add on, to access that class so that way I dont have to create a new object everytime I need to do that. Plus I know I dont want to rely on calling another class inside of one class. Here is an example The Super Class class OOP{ public function Login($pointer){ $Login->{$pointer}(); } public function Reports($pointer){ $Reports->{$pointer}() } } Login Class class Login extends OOP{ public function userLogin($user, $pass){ //Login code here //if error occurs, send it to Reports super::Reports(Error()); } } Reports Class class Reports extends OOP{ public function Error(){ //Send an error here } } Here is how I think I would call the class if a user was to login. $OOP = new OOP(); $OOP->Login(userLogin($user, $pass)); So now when I need to call any class I should be able to, correct? If you are confused about the top, then think of it this way: I am trying to create a class to where I can call or reference to ANY object now or in the future so I can add on and call that class from another class. Thank you for any help. Quote Link to comment https://forums.phpfreaks.com/topic/254951-access-different-classes-from-another-class/ Share on other sites More sharing options...
KevinM1 Posted January 13, 2012 Share Posted January 13, 2012 This is pretty much the antithesis to good OOP. The whole idea behind OOP is that objects are separate and don't know the internals of another object. Having child objects work back up the chain to call a superobject's (whose very name should be a warning sign) method is completely ass backwards. What you need to do is rename your OOP class to something better, and treat it as a Facade (it's a design pattern, google it)*. Then, make the Login and Report classes not inherit from it. The Facade's login method would delegate to the Login object and Report object as necessary. *You likely don't even need a Facade, but it depends on the complexity of your system. Quote Link to comment https://forums.phpfreaks.com/topic/254951-access-different-classes-from-another-class/#findComment-1307223 Share on other sites More sharing options...
The Little Guy Posted January 13, 2012 Share Posted January 13, 2012 I don't know if this is any help to you PHP 5.4+: http://www.php.net/manual/en/language.oop5.traits.php Quote Link to comment https://forums.phpfreaks.com/topic/254951-access-different-classes-from-another-class/#findComment-1307310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.