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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:02:03+00:00 2026-06-09T09:02:03+00:00

Is there a rule or guideline for when to use != instead of (!condition)

  • 0

Is there a rule or guideline for when to use != instead of (!condition) when checking if a condition is true or false?

For instance, I have some pages that check if TLS is enabled before returning anything:

if ($_SERVER['HTTPS'] !== 'on') { exit; }

But I could also write it like this:

if (!$_SERVER['HTTPS'] === 'on') { exit; }

For some statements it seems cleanest to use the latter, for instance:

if (!isset($_SESSION)) { session_start(); }

… is shorter than the equivalent:

if (isset($_SESSION) == false) { session_start(); }

Is there a standard or guideline for writing these statements, or is it just preference?

Note: I understand the difference between == and ===, I just want to make sure my code is as clear and concise as possible.

  • 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-09T09:02:04+00:00Added an answer on June 9, 2026 at 9:02 am

    Don’t do this:

    if (!$_SERVER['HTTPS'] === 'on') { exit; }
    

    ! has higher precedence than ===, so this evaluates to:

    if ((!$x) === 'on') { ... }
    

    In this case, !$x will cast $x to boolean, then invert it. So, if $x has anything at all in it, you’ll end up with:

    if (false === 'on') { ... }
    

    And this will never match for any value of $x.

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

Sidebar

Related Questions

There is a programming rule that says that a method should instead of asking
Is there some rule of thumb for that decision? I always stuck with this
Is there some rule when to use two functions or when to pass boolean
There is a rewrite rule ensuring that all URL's head to index.php and maintain
I have a rule, that gets up to three parts, separated by a /
Is there a rule in CSS that determines the cascading order when multiple classes
Is there a rule of thumb that .pas, .dfm and .dpr files should not
Is there a rule of thumb as to when one should use path parameters
This might be a stupid question, but is there a rule that states that
Is there any guideline or rule for when the view state should be enabled

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.