php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52069 DateTime::sub( ), DateTime::add( ), etc...
Submitted: 2010-06-12 22:05 UTC Modified: 2010-10-20 04:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: wdolek at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.2 OS: Fedora 12, 2.6.32.11-99
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wdolek at gmail dot com
New email:
PHP Version: OS:

 

 [2010-06-12 22:05 UTC] wdolek at gmail dot com
Description:
------------
http://www.php.net/manual/en/datetime.sub.php

documentation says:
DateTime::sub —  Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object 

Return Values
Returns the modified DateTime object or FALSE on failure. 

this is fine, but it is not clear that "sub" or "add" modify value on called instance, and then - really dont know why - returns that instance (again).


Test script:
---------------
$d1 = new DateTime();
$d2 = $d1->sub(new DateInterval('P1W'));

var_dump($d1);
var_dump($d2);

var_dump($d1 === $d2);

Expected result:
----------------
object(DateTime)[1]
  public 'date' => string '2010-06-12 22:01:55' (length=19)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Wdoltown' (length=13)

object(DateTime)[2]
  public 'date' => string '2010-06-05 22:01:55' (length=19)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Wdoltown' (length=13)

boolean false


Actual result:
--------------
object(DateTime)[1]
  public 'date' => string '2010-06-05 22:01:55' (length=19)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Wdoltown' (length=13)

object(DateTime)[1]
  public 'date' => string '2010-06-05 22:01:55' (length=19)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Wdoltown' (length=13)

boolean true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-13 15:43 UTC] derick@php.net
The reason why it returns the instance, is so that you can do for example:
$d->add("+2 days")->modify("next weekday")->sub("1 month");
 [2010-10-20 04:16 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=304524
Log: Fixed bug #52069 (DateTime::sub( ), DateTime::add( ), etc...)
 [2010-10-20 04:16 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2010-10-20 04:16 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=efc1a628ed146ff90a8bf8146fcfe9b6e6164425
Log: Fixed bug #52069 (DateTime::sub( ), DateTime::add( ), etc...)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 12:00:01 2026 UTC