Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8035135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:13:29+00:00 2026-06-05T02:13:29+00:00

Possible Duplicate: Why should a function have only one exit-point? As a CS student

  • 0

Possible Duplicate:
Why should a function have only one exit-point?

As a CS student I have had it beaten into my head that there should only be one exit point in a function, at the end.

eg. This:

function foo()
{

    //do stuff here

    if($bar)
    {
         $out = FALSE;
    }
    else
    {
         $out = TRUE;
    }
    return $out;
}

Not:

function foo()
{

    //do stuff here

    if($bar)
    {
         return FALSE;
    }
    return TRUE;
}

However I have seen this second type of exiting used quite often in other peoples code in php, and even in core code for some frameworks (like Kohana which I have been using lately).
Is this method of exiting a function considered okay in php standards?

Edit: I can see why I have been told not to do it as it can be easier to track some problems in a function with one exit point, other times I can see why it should be allowed as other problems are better solved or tracked in functions with multiple exit points.

Edit 2: Added “do stuff here” comments to the code example to make people happy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:13:31+00:00Added an answer on June 5, 2026 at 2:13 am

    I’ve always used the latter route, since you would have to declare $out and have one more variable in existence. But in retrospect, it’s just a boolean — it’s not doing any harm. The first route could look cleaner, depending on the context of your code.

    It all comes down to consistency. As long as you have a system, determining when it is time to use route 1 or route 2, you’re doing great.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Should a function have only one return statement? Hello, gcc 4.4.4 c89
Possible Duplicate: Should a function have only one return statement? This is what I
Possible Duplicate: How many lines of code should a function/procedure/method have? I would like
Possible Duplicate: Best practices in error reporting (Mathematica) Assume that I have a function
Possible Duplicate: Hash Function .NET hi, I should write an app that take string
Possible Duplicate: Why should I bother about serialVersionUID? I am using a class that
Possible Duplicate: When should one use final? When should Java programmers prefer to use
Possible Duplicate: Why can templates only be implemented in the header file? Why should
Possible Duplicate: returning multiple values from a function Suppose i have passed two values
Possible Duplicate: When should you use 'friend' in C++? I have come to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.