-3

I'm arriving in PHP world just now.

By the experiments I'm doing, I'm making some assumptions:

1- A PHP script is launched when the file it resides on is requested via http.

2- The script creates an independent scope for it's vars.

3- The script can only access any other DOM element at the end of it's execution. However, it can perform file's jobs any time.

Are those rights assumptions?

What other actions it can do while being executed?

Thanks.

v.k.
  • 2,826
  • 2
  • 20
  • 29
  • Well that seems very specific to me. 3 points that could almost be answered with yes or no. But well you know better :) – v.k. Jun 07 '15 at 18:49

1 Answers1

2

All of these assumptions are at least partially incorrect or, in the case of the last one, a bit nonsensical. You might want to find a good tutorial and also read through PHP The Right Way.

To address your assumptions in part:

1- A PHP script is launched when the file it resides on is requested via http.

Usually, but not necessarily. PHP files can also be run from the command line or via other protocols.

2- The script creates an independent scope for it's vars.

No. Any variables created outside of a function, class, or method have global scope and are automatically shared across any included or required files.

3- The script can only access any other DOM element at the end of it's execution. However, it can perform file's jobs any time.

This doesn't really make sense; PHP scripts don't have anything to with accessing the DOM. PHP runs purely on the server side. It can do anything on the server (assuming correct permissions, etc.) right up until it terminates.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • Thanks. I'll definitely read the pointed document. 1- I knew about that, thanks. 2- I don't really get the scope in a web page... Such a var exists in the page context? A js script could access it, for instance? 3- I meant if i echo in a while loop the page is only updated after the loop is finished... Anyway, thanks again, I'll read the doc and came back if needed. – v.k. Jun 07 '15 at 15:11
  • 1
    @v.k. Regarding your second point: No, JavaScript variables and PHP variables are completely separate animals. PHP processing all happens server-side, before any JavaScript executes. You can make a PHP variable available to JavaScript, however, by echoing it, like this ``. You can also use AJAX to pass variables from the server to the client. You can read more about scopes [in this question](http://stackoverflow.com/questions/16959576/reference-what-is-variable-scope-which-variables-are-accessible-from-where-and). – elixenide Jun 07 '15 at 15:18
  • Thanks once more. Digging in right now. :) I'm already using AJAX in this manner. – v.k. Jun 07 '15 at 15:20