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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:17:39+00:00 2026-05-28T06:17:39+00:00

This is perhaps a painfully basic question to answer, but I’m wondering about performance

  • 0

This is perhaps a painfully basic question to answer, but I’m wondering about performance issues regarding using PHP’s if identical !== versus if equal != to control flow.

Consider the following trivial PHP function:

<?php
 function test_json($json = NULL) {
  if ($json != NULL) {
   echo 'You passed some JSON.';
  } else {
   echo 'You failed to pass any JSON.';
  }
 }
?>

From a performance standpoint, is it preferable to employ if identical (!==) to prevent PHP iterating through variable types, attempting to find a valid comparison?

I assume that !== first compares the variable types, and if that fails, it immediately returns FALSE?
I’ve used != since PHP3 almost as a reflex. Now that I’m working on some much more computationally-intensive projects, minute performance considerations become more of a concern.

Other comments on flow control optimization are, of course, welcome!

  • 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-28T06:17:40+00:00Added an answer on May 28, 2026 at 6:17 am

    I haven’t done any performance tests on loose vs strict comparison operators, but for what you are trying to do, I would instead recommend something like

    if (!is_null($json)) {
        do_stuff()
    }
    

    More information on is_null() at http://www.php.net/manual/en/function.is-null.php

    EDIT: a note in the comments of the php page I linked to above has some results showing that the === operator is slightly faster than the == operator, both of which are faster than is_null(). However, another note points out that “The execution time difference between ===NULL and is_null is less than 250 nanoseconds. Go optimize something that matters.” I’d have to agree there. So all that said, I would suggest you go with what you deem to be the most readable.

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

Sidebar

Related Questions

I realize this perhaps a naive question but still I cant figure out how
This is perhaps similar to previous posts, but I want to be specific about
This is perhaps more of a discussion question, but I thought stackoverflow could be
Perhaps this question has been asked elsewhere, but I'm unable to find it. With
I have an ObjectDataSource (but perhaps this question is the same for all kinds
Perhaps this is a naive question. In my understanding, ASP.NET MVC cannot work with
Perhaps this has something to do with it being the mainForm, but I'll ask
[EDIT] Hmm. Perhaps this question should be titled what is the default user-input dialog
I'm a bit perplexed by drag and drop in wxPython (but perhaps this questions
This one seems painfully obvious to me, but for some reason I can't get

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.