Doc #52069 [Opn]: DateTime::sub( ), DateTime::add( ), etc...
| From: | derick@php.net | Date: | Sun, 13 Jun 2010 13:43:28 +0000 |
| Subject: | Doc #52069 [Opn]: DateTime::sub( ), DateTime::add( ), etc... | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4536@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52069&edit=1
ID: 52069
Updated by: derick@php.net
Reported by: wdolek at gmail dot com
Summary: DateTime::sub( ), DateTime::add( ), etc...
Status: Open
Type: Documentation Problem
Package: Documentation problem
Operating System: Fedora 12, 2.6.32.11-99
PHP Version: 5.3.2
New Comment:
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");
Previous Comments:
------------------------------------------------------------------------
[2010-06-12 22:05:04] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52069&edit=1