Jump to content

Question about self::


Liquid Fire

Recommended Posts

I have a class called data which every data class is going to extend from.  The 3 things is data class in 2 method(get, save) and then the member $_data_map.  The 2 function will help me get data from the database and insert in into a class and then using the data in the class, to save the data or update that data in the database, it will be using the $_data_map variable which will hold the database name which will point to an array the hold the class member name along with other things(like error code, default override value, etc...).  My question is can i access the user $_data_map in the parent class by using self::(because the call is technically coming from the user class not the data class) or do i need to pass the $_data_map to the function?

Link to comment
https://forums.phpfreaks.com/topic/61539-question-about-self/
Share on other sites

I'm not sure I follow you.  If $_data_map belongs to the children and not the parent then you won't be able to access it through self:: or $this-> you'll have to pass it to the parent through a virtual method.  However if every class uses $_data_map then that may suggest moving it into the parent class and either restricting its access completely in the children (For instance you could expose a protected Add and Remove method in the parent to interact with the state), or you could jsut make it protected.

Link to comment
https://forums.phpfreaks.com/topic/61539-question-about-self/#findComment-306883
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.