chaiwei Posted November 19, 2009 Share Posted November 19, 2009 Hi, I was concern about the php class. If I got a class which have 100 private variables, So normally with php magic function, I can public function __set($name , $value){ xxx } public function __get($name ){ xxx } So I don't have to have 100 set function and 100 get function. But with those magic function I wouldn't have to declare the variable inside the class, So I doesn't have the references for me to refer, so I tend to forget the variable naming. Like I name my employee id variable -> $empId May be my friend name the variable -> $employee_id So this is not the same. If we are using the same class to develop a employee system, May be my function can't pass the value to his function. How to overcome this issues with those magic function? Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 19, 2009 Share Posted November 19, 2009 You can use the magic __isset method to validate whether an attribute exists or not, calling it within your magic getters/setters. PS 100 attributes is a lot, do you really need that many? Quote Link to comment Share on other sites More sharing options...
chaiwei Posted November 20, 2009 Author Share Posted November 20, 2009 I see.. No.. it was just an example.. Let say an employee class, Should I seperate out the personal information class and job class (contract / permanent)? OR combine it inside an employee class? So if seperate I should use inheritance right? Another thing was If I am using those magic method, what is the difference for me to set those variable to public? Thanks for the advices. Quote Link to comment Share on other sites More sharing options...
chaiwei Posted November 23, 2009 Author Share Posted November 23, 2009 Normally I should seperate the job object and employee object to two different object right? Quote Link to comment 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.