|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45696 Allow method-chaining for misc. DateTime methods
Submitted: 2008-08-03 08:25 UTC Modified: 2008-08-03 16:45 UTC
From: mathieuk at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3CVS-2008-08-03 (CVS) OS: Mac OSX 10.5.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
41 + 17 = ?
Subscribe to this entry?

 [2008-08-03 08:25 UTC] mathieuk at gmail dot com
Feature request. 

Might be nice if the new DateTime::add(), DateTime::sub() and already 
existing DateTime::modify() methods would allow method chaining.

Reproduce code:
$datetime = new DateTime();
$interval = DateInterval::createFromDateString('2 weeks');

echo $datetime->add($interval)->format('d-m-Y H:i');

Expected result:
An echo'ed string showing the date of 2 weeks from 'now'.

Actual result:
Fatal error: Call to a member function format() on a non-object in 
/Users/mathieu/Source/tests/datetime/Modify.php on line 4


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-03 08:48 UTC]
It works for ->modify() already, and most of the other modification methods. Apparently I forgot to add it for ->add() and ->sub() though, so classifying this as a bug instead.

php -r 'echo date_create("")->modify("+3 weeks")->format("c\n");'

 [2008-08-03 16:45 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 13:01:29 2024 UTC