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 6234813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:33:26+00:00 2026-05-24T10:33:26+00:00

I was wondering how php processes if statements. If i were to have something

  • 0

I was wondering how php processes if statements.
If i were to have something such as:

if (isset($_GET['foo']) && $_GET['foo'] != $bar)

If foo isn’t set, would it then drop out of the if straight away (as it is an ‘and’ statement so it can’t succeed anyway) or would it also check the second part, rather pointlessly?

  • 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-05-24T10:33:28+00:00Added an answer on May 24, 2026 at 10:33 am

    What you’re describing is known as “short-circuit evaluation”.

    Most languages work this way, including PHP, so they will evaluate an expression until they are certain of the result, and then stop, so the remainder of the expression would not be evaluated.

    As you say, this is the most efficient approach.

    However, it can potentially throw a spanner in the works for inexperienced programmers, who nay try something like this:

    if(doFirstProcess() && doSecondProcess() {
        print "both processes succeeded";
    }
    

    In this case, the programmer is expecting both functions to be called, but if the first one returns false, then the second one will not be executed, as the program already knows enough to be certain of the final result of the expression, so it short-circuits the remainder of the expression.

    There are a few languages which don’t do short-circuit evaluation. VB6 was one example (back in the day). I don’t know about VB.Net, but since it’s evolved from VB6, I would suspect it would be similar. But aside from that, all other languages that I’ve worked with have used short-circuit evaluation, including PHP.

    There is a section in the PHP manual about this here: http://www.php.net/manual/en/language.operators.logical.php

    And you can read more on short circuit evalution here: http://en.wikipedia.org/wiki/Short-circuit_evaluation

    Hope that helps.

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

Sidebar

Related Questions

I'm in the process of making my PHP site Unicode-aware. I'm wondering if anyone
I'm wondering if PHP has this optimization built in. Normally when you call foreach
I am wondering how I can break up my index.php homepage to multiple php
I am wondering what the best way is using php to obtain a list
I'm wondering if there is an equivalent function to PHP's call_user_func() in ASP.NET application.
Been using PHP/MySQL for a little while now, and I'm wondering if there are
I've got quite a bit of PHP code laying around and am wondering at
I'm starting to learn about using Memcached with PHP and I was wondering; is
I am programming my first real PHP website and am wondering how to make
Been using PHP for quite some time now and I was wondering what this

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.