Table of Contents

PHP RFC: More Appropriate Date/Time Exceptions

Introduction

This RFC proposes to introduce Date/Time extension specific exceptions and errors where this makes sense.

Right now, they are either warnings/errors, or plain “Exception” or “Error”. This does not allow for catching Date/Time exceptions as they are not specific enough.

Out of scope of this RFC is changing and improving warning, Error, and Exception messages.

Proposal

The proposal is to reclassify warnings and errors as Exceptions, and introduce Date extension specific exceptions and errors.

The rationale behind all of these is the following:

The hierarchy will look like:

Procedural style use of date/time functions is not affected, and will continue to use warnings and errors as it currently does.

Backward Incompatible Changes

  1. The “Epoch doesn't fit in a PHP integer” now returns a new DateRangeError instead of a generic ValueError, which it does not subclass. This is only an issue for 32-bit platforms.
  2. The “Only non-special relative time specifications are supported for subtraction” warning with DateTime::sub() and date_sub() becomes a new DateInvalidOperationException. Leaving this with a warning and a NULL return is not useful behaviour.
  3. The “Unknown or bad format (%s) at position %d (%c): %s” and “String '%s' contains non-relative elements” warnings that are created while parsing wrong/broken DateInterval strings will now throw a new DateMalformedIntervalStringException when used with the OO interface, instead of showing a warning and returning false.

Proposed PHP Version(s)

Next PHP 8.x.

RFC Impact

No impact to any other extensions or opcode.

Open Issues

There are currently no open issues.

Unaffected PHP Functionality

Warnings and errors that are currently generated by the procedural versions of the Date/Time functionality are not impacted. Only the Object Orientated interface is.

Voting

To accept this RFC, and get more appropriate exceptions:

More Appropriate Date/Time Exceptions
Real name Yes No
alcaeus (alcaeus)  
asgrim (asgrim)  
ashnazg (ashnazg)  
cmb (cmb)  
crell (crell)  
derick (derick)  
galvao (galvao)  
girgias (girgias)  
heiglandreas (heiglandreas)  
ilutov (ilutov)  
kalle (kalle)  
mauricio (mauricio)  
mbeccati (mbeccati)  
nicolasgrekas (nicolasgrekas)  
ocramius (ocramius)  
reywob (reywob)  
sebastian (sebastian)  
sergey (sergey)  
svpernova09 (svpernova09)  
thekid (thekid)  
theodorejb (theodorejb)  
timwolla (timwolla)  
trowski (trowski)  
tstarling (tstarling)  
villfa (villfa)  
wjx (wjx)  
Final result: 25 1
This poll has been closed.

Vote started December 15th, and runs until December 31st, 24:00 UTC.

Patches and Tests

There is no patch yet.

Implementation

- Version: PHP 8.3 - Commit: https://github.com/php/php-src/commit/66a1a911f1d6cd4b89c0bb5577fa77f1d6a2cb96

Rejected Features

None yet.

ChangeLog

0.9.1