Jump to content

looping through class members(variables)?


Liquid Fire

Recommended Posts

I actually have an array that has the class members as the keys and that points to another array with information relating to the database, i am just going to use that since every class that extends from base_data needs that and that is the only class i need to be able to do the merge function on(which requires the looping).

 

On a side note for anyone else might be wanting this, you can use the ReflectionClass to get the properties of a class, it is a pretty nifty class for getting class information.

Link to comment
Share on other sites

As far as I know, ReflectionClass is buggy (as of 5.1) and hasn't had a stable release yet?

Btw this is a question rather than definitive answer.

 

I also thought that Reflection would only get public variables. Or at least that was the problem I was having with it last time I used it. Hopefully that's all fixed now.

 

I do feel however that you might as well make the internal members public if they are needed to be accessible, else you are sort of circumventing the reasoning behind member typing. Might as well go back to PHP 4 ;)

I don't know for sure as i can't see what it is you're attemping to do.

Link to comment
Share on other sites

I actually have an array that has the class members as the keys and that points to another array with information relating to the database, i am just going to use that since every class that extends from base_data needs that and that is the only class i need to be able to do the merge function on(which requires the looping).

 

This is not making any sense to me.

 

If you need to transfer data from a business object to the data layer, use a DTO. Basically you assemble an object from within a scope where the properties are visible (in the class itself or in the hierarchy), then provide an interface to fetch the transfer object. The data layer needs to know how to fetch the information from the DTO. Common practice would be to use default 'getters'.

 

This way you don't directly expose the members of the business object, yet still have a mechanism to retrieve the data to map to the database. The same can be done to reverse the process, i.e. restore the state of an object from a DTO created from persistent data out of the database.

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.