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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:56:03+00:00 2026-05-23T02:56:03+00:00

I know that !== is used to compare variable types too, while != only

  • 0

I know that !== is used to compare variable types too, while != only compares values.

But I see that many people use !== when they compare values, for example:

$stuff = 'foo';
if($stuff !== 'foo') // do...

Is there any reason they do this? Is !== faster than != or what?

  • 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-23T02:56:04+00:00Added an answer on May 23, 2026 at 2:56 am

    If you do know in advance that both variables are of the same type, then it won’t make any difference. I think the speed difference is just so negligible that the speed argument can (and should) be completely ignored, and you should focus on your application rather than focusing on premature (and unnecessary) optimization.

    However, if you do have a requirement that and argument should be exactly what you expect (for example, === false when you don’t want 0 to pass the equality test), then use === or !==.

    As mentioned by Headshota, if you are working with objects, then === checks that the two variables actually point to the same object instance, whereas == tries to match them by value, which might lead to unexpected results and should be used with great care. Here the strict operator will be used because it means something to the application.

    To answer your question, if in your particular context some people are using === or !== where you do know that both variables are of the same (scalar) type, then I guess it’s just a matter of coding style, and shows a bit of strictness in the code, enforcing the idea that both variables are of the same type, probably not with performance in mind.

    The strict operators have to be used when it means something to do so, not as a performance optimization.

    Update: to reply to the speed argument, let’s consider this small benchmark:

    $a = "test";
    $b = "test";
    
    $t = microtime(true);
    for ($i=0; $i<1e6; $i++) {
        ($a == $b);
        // (100x the equality test, omitted for clarity purposes,
        //  to lower the speed impact of the loop itself)
        ($a == $b);
    }
    printf('%.3f', microtime(true)-$t);
    

    I roughly get:

    6.6 seconds for ==
    4.3 seconds for ===
    

    Now if I use $b = 1; to force an implicit conversion, I get roughly:

    4.4 seconds for ==
    2.4 seconds for ===
    

    This means roughly a 2 seconds gain in both cases. You might think, and you will be right in some way, that this is a demonstration of the speed advantage of the strict comparison operator. But don’t forget that we are talking about 1e6 * 100 = 100 million iterations.

    That means that a single strict comparison will speed up your script by 0.00000002 seconds.

    If you think that this is something you should consider when writing your script, then do so. But you’ll soon encounter other tiny optimizations that will give you 1000 times this speed gain, and make such “optimizations” look useless. This is a textbook case of premature optimization.

    Again, use the strict comparison operators if you have to, because it is a requirement in your code. Do not use it for performance reasons.

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

Sidebar

Related Questions

I know it is commonly used as a lock object, but is that really
I know that ISKINDOF() function is used to compare two class objects that is
I searched over .... I see many advantages, but it seems that all the
I know that python has a len() function that is used to determine the
I know that CSS can be used to control the presentation of (X)HTML in
I know that jQuery.extend can be used to add by own custom methods to
In other words, can fn() know that it is being used as $var =
Does anyone know of any software that can be used to create Agile User
Does anyone know of any existing packages or libraries that can be used to
Does anyone know of an MD5/SHA1/etc routine that is easily used with GLib (i.e.

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.