2

Just a simple question which Im sure I already know the answer to, but would like to confirm popped into my head.

In a PHP script, it doesn't matter what order you write your code in. Lets say, you can call a function on line 10, and define the function itself on line 20. Still, it will run the function instead of throwing an error saying that the function is undefined.

So, when running a php-script, does the server first read through all the content of the script and included files first, and then run through it once more to fire the events?

Ole Haugset
  • 3,709
  • 3
  • 23
  • 44
  • 6
    Not server itself, but PHP parser. But yes, code is read two times, first to map variables, second to execute code. – Justinas Oct 09 '14 at 10:47
  • 3
    I hope this will help you http://stackoverflow.com/questions/2720488/how-exactly-is-a-php-script-executed – Shafeeque Oct 09 '14 at 10:48
  • It parses and compiles the script file before executing it, but not included files.... they're only parsed, compiled and executed at the point where the include statement is executed in the main script – Mark Baker Oct 09 '14 at 10:48
  • It reads and compiles only the main file. The included files are read and parsed during runtime, when the `include`/`require` statement is reached (if it is reached). – axiac Oct 09 '17 at 08:18

0 Answers0