简体   繁体   中英

What are the performance impacts of declaring variables before <html> tag?

What's the best practice regarding declaring variables at the top of the doc? Is there a performance impact if variable such as $GET or $POST are declared before the html tag?

No, there is no performance impact, why would there be? Your PHP script is completely independent of the HTML code (it is just text for PHP). However, you should really consider separating your coded logic and your HTML code in order to achieve greater maintainability. You can use any php template engine for that purpose.

  1. You don't really declare Superglobals in PHP. PHP populates them for you before your scripts execute.

  2. I presume you mean doing something like $var = $_GET['var']; . You will not be able to measure the negligible amount of time that PHP takes to re-assign the value from the Superglobal to the variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM