Do we need to explicitly call a “return;” in a constructor? If Yes Then Why, I need a complete reason behind this.
I am working in PHP but I would like to know how this concept works in others as well?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t have to call return explicitly in any of those languages. It is implicit at the end of the function/method body.
If you call return before the end of the body of code, you can prevent anything else from running. But you don’t want to leave the object in an inconsistent state. Instead throw an exception for an error case.