spatie / period

Complex period comparisons
https://spatie.be/open-source
MIT License
1.55k stars 72 forks source link

Grab properties of Period object #95

Closed amirakbulut closed 2 years ago

amirakbulut commented 2 years ago

Hi,

Why are all the properties of the Period object protected?

For example, I want to grab the start & end of a Period object.

$period = Period::make('2021-11-01 08:00:00', '2021-11-01 18:00:00', Precision::MINUTE(), Boundaries::EXCLUDE_ALL());

$period->start returns:

Uncaught Error: Cannot access protected property Spatie\Period\Period::$start 

$period->end returns:

Uncaught Error: Cannot access protected property Spatie\Period\Period::$end 

I tried $period->getStart() as well, which returns:

Uncaught Error: Call to undefined method Spatie\Period\Period::getStart()

Why?

brendt commented 2 years ago

You need to use ->start() and ->end(): https://github.com/spatie/period/blob/master/src/PeriodTraits/PeriodGetters.php#L36