PHP constant problem: Const and define contrast, ask for advice

Source: Internet
Author: User
Only for the speed problem, as for the usage for the time being, see online Some people say that const belongs to the structure of grammar, the speed will be higher than define function several times, I need a professional argument, is it true? Now that const can be used outside of the class, is it a priority when you define constants?

Reply content:

Only for the speed problem, as for the usage for the time being, see online Some people say that const belongs to the structure of grammar, the speed will be higher than define function several times, I need a professional argument, is it true? Now that const can be used outside of the class, is it a priority when you define constants?

For speed comparisons, I suggest that you can write a few lines of code yourself under test, much better than asking here.

  • Speed:

    • If the const fast, is also a subtle gap, it doesn't make much sense to consider this

    • If the const is better, the document will also recommend you to use, but no, so don't tangle

  • Will it be preferable to use const:

    • According to the current differences, personal habits, as long as the use of the norms can be followed

1. Expressions can now be used in 2 different ways;
2.const can define arrays, define can only define scalar

Even if the grammatical structure is faster than a function call, then the const and define () are trivial differences, rather than trivial performance trivial, it is better to optimize the following table structure and SQL statements come true.

  • 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.