When do you need to determine the return value of a function (method) when you are programming?

Source: Internet
Author: User
In programming, it is necessary to frequently call the function or method, for the robustness of the program, generally to the function of the return value of the judgment (especially for those who return bool value of the function), but each call function to determine the return value? This is not only cumbersome, but also to get the program code everywhere is the judgment statement, so want to ask, in the Call function (method), when should judge its return value, when not needed, thank:)

Reply content:

In programming, it is necessary to frequently call the function or method, for the robustness of the program, generally to the function of the return value of the judgment (especially for those who return bool value of the function), but each call function to determine the return value? This is not only cumbersome, but also to get the program code everywhere is the judgment statement, so want to ask, in the Call function (method), when should judge its return value, when not needed, thank:)

Look forward to PHP7.

function test(int $a,int $b) : bool {    return $a > $b;}

Saying goes has. is a little more than the candle.
In a function, any non-successful handling throws an exception. Subsequent calls to the function do not need to be judged.

PHP is a weak type of language, in the code usually through if (function_name ($params)) {} to determine whether the return value is required, there is no need to tangle too much.

  • 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.