Variable Scope

Variable scope is a tricky but important concept. Every variable in PHP has a scope to it, which is to say a realm in which the variable (and therefore its value) can be accessed. As a rule of thumb, every variable has the scope of the page in which it resides. In other words, you can refer to a variable anywhere within a script once you’ve defined it (set its value). Assuming your PHP configuration has register_globals turned on, your form values can be accessed anywhere within the handling page.

Since included files act as if they were part of the original (including) script, variables defined before the include line are available to the included file. Further, variables defined within the included file are available to the ...

Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.