Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Davey Shafik:
An Exceptional Change in PHP 7.0
Jul 31, 2015 @ 09:55:37

Davey Shafik has a post today that talks about an exceptional change to PHP 7.0 and some updates that have been made to provide more of a hierarchy (a different one) that can make them easier to work with.

With PHP 7 errors and exceptions are undergoing major changes. For the first time, the PHP engine will start to emit exceptions instead of standard PHP errors for (previously) fatal, and catchable fatal errors. This means that we can now handle them much more gracefully with try... catch. But with this change, comes a whole new exception hierarchy.

He provides a tree of the error/exception relationships, what they inherit from and who their "children" are. He also talks more in detail about the "error" type exceptions: Error, AssertionError, ParseError and TypeError. He gets into more detail about catchable fatal errors and the userland handling of the Throwable type and extension.

tagged: exception change php7 throwable error exception tree parent child

Link: http://daveyshafik.com/archives/69237-an-exceptional-change-in-php-7-0.html

Davey Shafik:
Changes to Engine Exceptions in PHP 7.0alpha2+
Jul 06, 2015 @ 09:41:29

Davey Shafik has posted about some changes in engine exceptions in the latest alpha of PHP 7 (alpha2+), mainly a small change to how things are named.

While updating my PHP 7 talk “What to Expect When You’re Expecting: PHP 7″ for the DutchPHP Conference 2 weeks ago I noticed a small but significant change to the new Engine Exceptions feature in the newly release alpha 2. [...] However, for alpha2 this hierarchy changed. Engine Exceptions lost their “Exception” suffix, and became Error and and *Error exceptions, and the abstract BaseException class was changed to a Throwable interface.

He points out that this new naming and structure makes it impossible to make a good hierarchal structure for exceptions. He does favor the new format, though, as it does allow for some structure via interface definitions.

tagged: exception handling php7 alpha2 throwable handling hierarchy

Link: http://daveyshafik.com/archives/69185-changes-to-engine-exceptions-in-php-7-0alpha2.html

Aaron Piotrowski:
Throwable Exceptions and Errors in PHP 7
Jun 29, 2015 @ 11:45:32

Aaron Piotrowski has a new post to his site talking about a feature of the next major release of the PHP language (PHP 7) around error and exception handling: working with throwable exceptions and errors.

Handling fatal errors in the past has been next to impossible in PHP. A fatal error would not invoke the error handler set by set_error_handler() and would simply halt script execution.

In PHP 7, an exception will be thrown when a fatal and recoverable error (E_ERROR and E_RECOVERABLE_ERROR) occurs, rather than halting script execution. Fatal errors still exist for certain conditions, such as running out of memory, and still behave as before by immediately halting script execution. An uncaught exception will also continue to be a fatal error in PHP 7. This means if an exception thrown from an error that was fatal in PHP 5.x goes uncaught, it will still be a fatal error in PHP 7.

He goes on to talk about the new interface that both Fatals and Errors implement to make catching them possible in PHP7: Throwable. He provides an example of what the interface would look like in PHP code and how to catch them (a simple try/catch). He then gets into each of the types and looks at the error and exception types they cover including TypeError, ParseError and AssertionError. He also includes an interesting part at the end of the post showing you how to write your error/exception handling to work correctly with both PHP 5 and PHP 7 at the same time.

tagged: throwable exception error php7 catch try interface introduction

Link: https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/