This works:
$aWeekAfterDate = new DateTime();
$aWeekAfterDate->modify('+1 week');
$aWeekAfterDate->format('d.m.Y');
But this:
$aWeekAfterDate = new DateTime();
$aWeekAfterDate->modify('+1 week')->format('d.m.Y');
Gives me this error:
Fatal error: Call to a member function format() on a non-object in ... on line ...
Fatal error (shutdown): Call to a member function format() on a non-object in ... on line ...
I have looked up the DateTime::modify method in the documentation and its return value is this:
Returns the DateTime object for method chaining or FALSE on failure.
Why is method chaining not working?
I am using PHP version 5.2.6.
Changelog
Version Description
5.3.0 Changed the return value on success from NULL to DateTime.
So returning the DateTime object for chaining was only introduced in PHP 5.3.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With