PHP RFC: Throw Error in Extensions
Version: 0.1
Date: 2016-06-14
-
Status: Accepted
-
Introduction
With PHP 7, most fatal and recoverable errors in the engine where changed to instead throw an instance of Error
. However this change was only made in the engine. Extensions still use fatal and recoverable errors instead of throwing exceptions.
Proposal
This RFC proposes changing most conditions raising an E_ERROR
or E_RECOVERABLE_ERROR
errors to throw an instance of Error
instead. Conditions due to memory errors or other unrecoverable errors will still remain fatal errors.
Below is a list of extensions and what conditions were changed to throw an instance of Error instead of a fatal or recoverable error.
Date:
Invalid serialization data for a DateTime or DatePeriod object will now throw an instance of Error from __wakeup() or __set_state() instead of resulting in a fatal error.
Timezone initialization failure from serialized data will now throw an instance of Error from __wakeup() or __set_state() instead of resulting in a fatal error.
DOM:
Invalid schema or RelaxNG validation contexts will throw an instance of Error instead of resulting in a fatal error.
Attempting to register a node class that does not extend the appropriate base class will now throw an instance of Error instead of resulting in a fatal error.
Attempting to read an invalid or write to a readonly property will throw an instance of Error instead of resulting in a fatal error.
IMAP:
Intl:
Failure to call the parent constructor in a class extending Collator before invoking the parent methods will throw an instance of Error instead of resulting in a recoverable fatal error.
Cloning a Transliterator object may will now throw an instance of Error instead of resulting in a fatal error if cloning the internal transliterator fails.
Session:
Custom session handlers that do not return strings for session IDs will now throw an instance of Error instead of resulting in a fatal error when a function is called that must generate a session ID.
An invalid setting for session.hash_function will throw an instance of Error instead of resulting in a fatal error when a session ID is created.
SPL:
Attempting to clone an SplDirectory object will throw an instance of Error instead of resulting in a fatal error.
Calling ArrayIterator::append() when iterating over an object will throw an instance of Error instead of resulting in a fatal error.
Standard:
assert() will throw a ParseError when evaluating a string given as the first argument if the PHP code is invalid instead of resulting in a catchable fatal error.
Calling forward_static_call() outside of a class scope will now throw an instance of Error instead of resulting in a fatal error.
Backward Incompatible Changes
Generally none, though it is possible some exceptions thrown could be unintentionally caught by code written for PHP 7. However, it is rare for Error
exceptions to be caught outside of cleanup or logging, so catching these exceptions is likely desirable over a fatal error.
Proposed PHP Version(s)
Voting
A majority of 50%+1 is required to approve this RFC.
Voting opened on 2016-06-27 at 4:00 pm GMT and will remain open until 2016-07-04 at 11:59 pm GMT
Patches and Tests
References