简体   繁体   English

之前声明变量会对性能产生什么影响 <html> 标签?

[英]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? 如果在html标记之前声明$ GET或$ POST之类的变量,会对性能产生影响吗?

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). 您的PHP脚本完全独立于HTML代码(这只是PHP的文本)。 However, you should really consider separating your coded logic and your HTML code in order to achieve greater maintainability. 但是,您应该真正考虑将编码逻辑和HTML代码分开,以实现更大的可维护性。 You can use any php template engine for that purpose. 您可以为此目的使用任何php模板引擎。

  1. You don't really declare Superglobals in PHP. 您实际上并没有在PHP中声明Superglobals。 PHP populates them for you before your scripts execute. 在脚本执行之前,PHP会为您填充它们。

  2. I presume you mean doing something like $var = $_GET['var']; 我想你的意思是做类似$var = $_GET['var'];事情$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. 您将无法测量PHP将值从Superglobal重新分配给变量所花费的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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