mdmcginn Posted August 20, 2009 Share Posted August 20, 2009 Working with somebody else's object-oriented PHP calendar system, I want to display the title of an event, but can't find the right syntax. Not that I particularly know what I'm doing.... The results of print_r($this->output); begin with: Array ( [0] => Calendar_EventInstance Object ( [event] => Calendar_Event Object ( [__table] => event [id] => 64 [title] => Summer Camp [subtitle] => For High School Juniors [othereventtype] => [description] => This camp helps young people gain programming skills (etc.) What's the correct syntax? I've tried: <?php echo Calendar_Event->output->title; ?> <?php echo Calendar_EventInstance::Calendar_Event::$this->output->title; ?> <?php echo $this->output->title; ?> As I said, I'm kind of in the dark here. I try to copy syntax from other parts of the code, but either the line or the page is blank. Quote Link to comment https://forums.phpfreaks.com/topic/171214-syntax-for-displaying-oop-object-member/ Share on other sites More sharing options...
mdmcginn Posted August 24, 2009 Author Share Posted August 24, 2009 I tried it a different way, but <?php echo $this->output->title; ?> didn't give any output either. Quote Link to comment https://forums.phpfreaks.com/topic/171214-syntax-for-displaying-oop-object-member/#findComment-905381 Share on other sites More sharing options...
KevinM1 Posted August 24, 2009 Share Posted August 24, 2009 In OOP, you don't typically access a data member directly. Publicly accessible members break encapsulation, which is one of the main points of OOP. You need an accessor method (function). Does this calender have a getTitle function, or something similar? Quote Link to comment https://forums.phpfreaks.com/topic/171214-syntax-for-displaying-oop-object-member/#findComment-905412 Share on other sites More sharing options...
mdmcginn Posted August 26, 2009 Author Share Posted August 26, 2009 No, the code says: <!-- Main output for the view determined by determineView() and populated with run() --> <?php Calendar::displayRegion($this->output); ?> So I guess that's where I better look for the appropriate accessor method, or the appropriate model for writing my own. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/171214-syntax-for-displaying-oop-object-member/#findComment-906977 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.