Reputation: 25
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?
Upvotes: 1
Views: 127
Reputation: 25781
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.
Upvotes: 4
Reputation: 18964
You don't really declare Superglobals in PHP. PHP populates them for you before your scripts execute.
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.
Upvotes: 1