php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50020 DateInterval:createDateFromString() silently fails
Submitted: 2009-10-27 17:35 UTC Modified: 2019-02-28 14:02 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: jennifer dot kimball at nrc dot ca Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.0 OS: Solaris 10
Private report: No CVE-ID: None
 [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)

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-27 22:31 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Works just fine for me. 
 [2009-10-30 18:33 UTC] jennifer dot kimball at nrc dot ca
The snapshot fixes the memory problem for me. But there is still no way to easily tell if a DateInterval size is zero or if there were errors creating the DateInterval.
 [2010-11-24 10:29 UTC] jani@php.net
-Package: Feature/Change Request +Package: Date/time related
 [2014-04-24 10:09 UTC] datibbaw@php.net
-Status: Open +Status: Feedback
 [2014-04-24 10:09 UTC] datibbaw@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Couldn't reproduce the memory issue from 5.3.0 onwards: http://3v4l.org/kPMor
 [2014-04-24 10:13 UTC] datibbaw@php.net
Sorry, I somehow missed the comment thread (was looking at the wrong tab) ;-)
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2018-07-27 11:06 UTC] nyamsprod at gmail dot com
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.
 [2018-07-27 11:13 UTC] requinix@php.net
-Status: No Feedback +Status: Re-Opened -Type: Feature/Change Request +Type: Bug
 [2018-07-27 11:13 UTC] requinix@php.net
The memory problem is gone but there's still no way to detect failure - error information generated when processing the string is discarded and should be used to decide whether to return false.
 [2019-02-28 14:02 UTC] derick@php.net
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: derick
 [2019-02-28 14:02 UTC] derick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC