Jump to content

php set and get function


chaiwei

Recommended Posts

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.