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

  • SEARCH
  • Home
  • 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 8166285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:48:36+00:00 2026-06-06T19:48:36+00:00

Suppose I have a conditional statement without brackets in a function: function get_user_id() {

  • 0

Suppose I have a conditional statement without brackets in a function:

function get_user_id() 
{
    if ($something) $this->some_function($str);
    return array('user_id' => $user_id);
}

I think bracketless statements are bad practice… I want to add brackets to the if-statement but where does the statement end? Does is it end at the first semicolon or the end of the function?

Which is correct:

function get_user_id() 
{
    if ($something)
    {
       $this->some_function($str);
    }
    return array('user_id' => $user_id);
}

or..

function get_user_id() 
{
   if ($something)
   {
      $this->some_function($str);
      return array('user_id' => $user_id);
   }           
}
  • 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-06T19:48:39+00:00Added an answer on June 6, 2026 at 7:48 pm

    The first version is correct, as without braces, only one statement after the if statement applies to the conditions of the if statement.

    So this:

    if ($something) $this->some_function($str);
    

    Is equivalent to:

    if ($something) {
        $this->some_function($str);
    }
    

    I do agree that the manual is a bit vague about this, but its example is about a single statement, and mentions that in order to incorporate additional lines to the same conditional, you would need a “statement group”, denoted by curly braces:

    Often you’d want to have more than one statement to be executed
    conditionally. Instead, you can group several statements into a
    statement group.

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

Sidebar

Related Questions

Suppose I have this function: std::string Func1(std::string myString) { //do some string processing std::string
suppose i have a .on() function wherein i select multiple ids $(#i, #am, #your,
This question pertains primarily to good design. Suppose I have a controller action like
This is driving me nuts, I have a login function that checks to make
Suppose I have this code executed by two different threads T1 and T2 that
Suppose we have a well-defined probability distribution that is conditional upon a certan parameter:
Suppose I have a collection (be it an array, generic List, or whatever is
Suppose that I have a Java program within an IDE (Eclipse in this case).
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
I am having trouble mixing c# functions with conditions in Linq-To-SQL suppose i have

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.