0

I have a object with protected property that I want to get dateTime.

1)modelData->start->dateTime //2017-05-10T17:00:00+05:30
2)modelData->end->dateTime //2017-05-10T17:20:00+05:30

The object looks like

Google_Service_Calendar_Event Object
(
    [collection_key:protected] => recurrence   
    [attachmentsType:protected] => Google_Service_Calendar_EventAttachment   
    [created] => 2017-05-08T07:05:43.000Z
    [creatorType:protected] => Google_Service_Calendar_EventCreator
    [creatorDataType:protected] => 
    [description] => 
    [endType:protected] => Google_Service_Calendar_EventDateTime
    [endDataType:protected] => 
    [endTimeUnspecified] => 
    [etag] => "2988454353000000"
    [extendedPropertiesType:protected] => Google_Service_Calendar_EventExtendedProperties
    [extendedPropertiesDataType:protected] => 
    [gadgetType:protected] => Google_Service_Calendar_EventGadget   
    [visibility] => 
    [internal_gapi_mappings:protected] => Array
        (
        )

    [modelData:protected] => Array
        (
            [creator] => Array
                (
                    [email] => pickzy.nettest@gmail.com
                    [self] => 1
                )

            [organizer] => Array
                (
                    [email] => pickzy.nettest@gmail.com
                    [self] => 1
                )

            [start] => Array
                (
                    [dateTime] => 2017-05-10T17:00:00+05:30
                    [timeZone] => Asia/Calcutta
                )

            [end] => Array
                (
                    [dateTime] => 2017-05-10T17:20:00+05:30
                    [timeZone] => Asia/Calcutta
                )

            [reminders] => Array
                (
                    [useDefault] => 1
                )

        )

)

PHP Script:

I can get etag value without producted

echo "-----".$result->getEtag(); //"2988454353000000" 

I cannot get start and end value with producted

echo "-----".$result = $event->getData(); //Error undefined method

My Refer:

Get string within protected object

How to get protected property of object in PHP

Please advice!

Community
  • 1
  • 1
Ramalingam Perumal
  • 1,345
  • 1
  • 17
  • 39

1 Answers1

2

Visibility

Members declared protected can be accessed only within the class itself and by inheriting classes.

If you need to access the property from outside, pick one: •Don't declare it as protected, make it public instead •Write a couple of functions to get and set the value (getters and setters)

If you don't want to modify the original class (because it's a third-party library you don't want to mess) create a custom class that extends the original one:

class My_Google_Service_Calender_Event extends Google_Service_Calendar_Event {
}
Osama
  • 2,629
  • 1
  • 8
  • 14