Is there a difference in efficiency between if (1== $user) and if ($user ==1) in a PHP program?

Source: Internet
Author: User
I've seen both of them.

Reply content:

There's no difference in efficiency.
--------------

if (1== $user)
In programming, if you forget a =, the program will error

if ($user ==1)
If you forget a =, you may never find it.

is to use programming habits to reduce the code of the error, reduce the accidental bug I have to manually test the verification under:

  
   
in pursuit of performance to this point, you have to change the language it! In a dynamic language like PHP, how does it hurt to compare this efficiency problem? The efficiency of considering this situation is meaningless thanks to the invitation! Although no such tests have been done, there should be no difference in efficiency. Appreciate this attitude of the landlord.
$ time php test.phpreal 0m12.352suser 0m0.000ssys 0m0.015s$ time PHP test1.phpreal 0m12.240suser 0m0.000ssys 0m0.031s$ time php test2.phpreal 0m4.635suser 0m0.015ssys 0m0.0 00s$ time PHP test3.phpreal 0m4.620suser 0m0.000ssys 0m0.015s  
It's hard to see the difference in efficiency. The main purpose of this writing is to avoid the = =, after all, when the dizzy eye looks like a $ A = 1 is very similar to the right, and 1 = $a no matter how dizzy you are or will feel wrong.
In addition to this habit exists not only in the writing of PHP, in other languages is also very common this does not involve the efficiency problem, this is a code habit, in order to prevent hand errors, will be written = =, this error is all C and C derivative language or C language programmers have made mistakes ~ ~
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.