Re: A Few Noob Questions [message #175148 is a reply to message #175127] |
Tue, 16 August 2011 21:30 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Tue, 16 Aug 2011 11:02:40 -0400, eBob.com wrote:
> How can the "units" of PHP between tags communicate? Can my PHP code
> create $GLOBALS variables? How about $_SESSION variables?
PHP processes a file. Within a file, you may have bunches of php code
between "<?php" and "?>" tags, and may also have text output. The php
code may include other files in various ways.
All the code in the file, including in any included files, that is not
part of a separate function definition operates in the same variable
context.
So, assuming between these cutlines is a single file:
------------8<------------
<?php
$a = 6;
?>
output this text
<?php
echo $a . "\n"; // uses the previously defined value for $a
?>
------------8<------------
If I save that as "basic.php" and then execute it in the cli:
~$ php basic.php
output this text
6
~$
Rgds
Denis McMahon
|
|
|