Jump to content

Syntax for displaying OOP object member


mdmcginn

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/171214-syntax-for-displaying-oop-object-member/
Share on other sites

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?

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.

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.