play_ Posted December 3, 2011 Share Posted December 3, 2011 What would be the simplest way? Do you use a method in the child class? Personally I use parent::$this->whatever; But I was wondering what you guys do. Link to comment https://forums.phpfreaks.com/topic/252415-ways-to-get-parent-class-variables/ Share on other sites More sharing options...
xyph Posted December 4, 2011 Share Posted December 4, 2011 That's the correct way. Personally, I don't use inheritance often. I prefer using interfaces, and other ways off class interaction. Link to comment https://forums.phpfreaks.com/topic/252415-ways-to-get-parent-class-variables/#findComment-1294118 Share on other sites More sharing options...
scootstah Posted December 4, 2011 Share Posted December 4, 2011 Why not just do $this->var? Link to comment https://forums.phpfreaks.com/topic/252415-ways-to-get-parent-class-variables/#findComment-1294136 Share on other sites More sharing options...
trq Posted December 4, 2011 Share Posted December 4, 2011 AS scootstah has pointed out a parents properties are available as if they are defined within the child class. parent::$this->whatever; Does make allot of sense. Maybe show us a simple example of what it is your referring to because really, to access a parents property is no different than accessing any other property. eg; $this->var; Link to comment https://forums.phpfreaks.com/topic/252415-ways-to-get-parent-class-variables/#findComment-1294196 Share on other sites More sharing options...
KevinM1 Posted December 4, 2011 Share Posted December 4, 2011 Caveat: a parent's variables (and functions) are available to their children if they're marked as public or protected. Private members aren't shared. Link to comment https://forums.phpfreaks.com/topic/252415-ways-to-get-parent-class-variables/#findComment-1294203 Share on other sites More sharing options...
trq Posted December 4, 2011 Share Posted December 4, 2011 I assumed that was obvious. Link to comment https://forums.phpfreaks.com/topic/252415-ways-to-get-parent-class-variables/#findComment-1294411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.