PHP constant problems: const and define comparison and advice

Source: Internet
Author: User
Tags define function
I only want to solve the speed problem. I don't mention the usage for the moment. someone on the Internet said that Const is a structure syntax and the speed will be several times higher than the define function. I need a professional saying, is that true? Currently, const can be used outside the class. Will it be used preferentially when you define constants? I only want to solve the speed problem. I don't mention the usage for the moment. someone on the Internet said that Const is a structure syntax and the speed will be several times higher than the define function. I need a professional saying, is that true? Currently, const can be used outside the class. Will it be used preferentially when you define constants?

Reply content:

I only want to solve the speed problem. I don't mention the usage for the moment. someone on the Internet said that Const is a structure syntax and the speed will be several times higher than the define function. I need a professional saying, is that true? Currently, const can be used outside the class. Will it be used preferentially when you define constants?

For speed comparison, I suggest you write a few lines of code for testing, which is much better than asking here.

  • Speed:

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

    • If the const is better, you will also be recommended in the document, but no, so do not tangle

  • Will it give priority to const:

    • According to the current difference, personal habits, as long as you follow the various use specifications

1. expressions can be used in both methods;
2. const can define arrays, and define can only define scalar

Even if the syntax structure is faster than the function call, the const and define () are also insignificant differences. it is not a trivial matter to tangle with this. it is better to optimize the table structure and SQL statements.

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.