|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-27 17:35 UTC] jennifer dot kimball at nrc dot ca
Description:
------------
Documentation of DateInterval:createDateFromString() does not state what happens when the function fails. So far as I can tell, it seems to produce an empty DateInterval object.
If an empty object is the expected behaviour then it should be documented. And more importantly, there should be an easy way to test if the object is empty.
Given that creating a DatePeriod using an empty DateInterval consumes all the memory available to a session, it seems to me that allowing empty DateIntervals is a design flaw.
Reproduce code:
---------------
---
From manual page: dateinterval.createfromdatestring#Return Values
---
$i=DateInterval::createFromDateString('P1D');//expected to fail
$d1=date_create('2009-10-27');
$d2=date_create('2009-11-15');
$p=new DatePeriod($d1,$i,$d2); //PHP times out
Expected result:
----------------
expect error at line $i=DateInterval::createFromDateString('P1D')
Actual result:
--------------
Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 72 bytes)
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
var_dump(date_interval_create_from_date_string('foobar') == new DateInterval('PT0S')); I would expect date_interval_create_from_date_string to return false I would expect DateInterval::createFromDateString to return null or to throw an Exception. Currently you cannot distinguish between a DateInterval with 0s duration and a failed parsing of the duration string.