New PHP Features: The use of the Finally keyword

Source: Internet
Author: User

This article brings the content is about PHP new features: The use of the Finally keyword, there is a certain reference value, the need for friends can refer to, I hope to help you.

Recently, I submitted to the finally Rfc:supports finally keyword has been submitted to the PHP backbone, today to introduce you the background of this new feature, and how to use.
The demand for this feature was first proposed in 2005: FR #32100, but no one has ever realized it. Last month, someone came up, I was holding a try attitude to achieve a bit, because someone told me, has not been achieved, one reason is because it is difficult to achieve (perhaps for a yard, like to challenge the problem, is nature, hehe).
For PHP now, if we need to do something about the exception that we can't handle at the moment, we'll write a code like this:

function Anonymous () {try {  function_may_throw_exception ();  } catch (Exception e) {  Clearup ();  throw e;  } Clearup ();  }

We see that we need to explicitly write two Clearup (). Then finally we can solve the problem.
Finally is not the original PHP, C #, Javascript, Java. And so on other languages, PHP's finally is similar to other languages.
For finally, a more confusing place to return in the finally, because finally must be guaranteed to be executed, so if we return in the try, finally will be called, So what if finally also return? What is the value of the last return? In PHP, if you return in Finally, the original return value will be overwritten.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.