huisjames
huisjames

Reputation: 25

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?

Upvotes: 1

Views: 127

Answers (2)

fresskoma
fresskoma

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

Stephen
Stephen

Reputation: 18964

  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.

Upvotes: 1

Related Questions