Reputation: 1427
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] => [email protected]
[self] => 1
)
[organizer] => Array
(
[email] => [email protected]
[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!
Upvotes: 0
Views: 5153
Reputation: 3030
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 {
}
Upvotes: 2