|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 08 09:00:02 2026 UTC |
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");