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

Laravel News:
PHP 7.3: A Look at JSON Error Handling
Jun 13, 2018 @ 15:18:53

On the Laravel News site there's a tutorial posted looking ahead at PHP 7.3 and some of the changes coming for JSON error handling.

One of the new features coming to PHP 7.3 is better error handling for json_encode() and json_decode(). The RFC was unanimously accepted by a 23 to 0 vote. Let’s take a look at how we handle JSON errors in <= PHP 7.2, and the new improvements coming in PHP 7.3.

They start with an example of how PHP developers would normally check for JSON parsing errors and the typical response when it fails. In the proposed functionality for PHP 7.3 and optional JSON_THROW_ON_ERROR would be added to throw a JsonException if there was an issue parsing the provided data. This also means that you no longer need to manually request the error message, it would just come through as a part of the standard exception. You can find out the full details on the change in the RFC.

tagged: php73 json parse error handling throwable exception feature rfc

Link: https://laravel-news.com/php-7-3-json-error-handling

Davey Shafik:
An Exceptional Change in PHP 7.0
Jul 31, 2015 @ 14: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 @ 14: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 @ 16: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/


Trending Topics: