Hi,
We know that variables are declared inside a function, is known to have a Local scope.
Ok?,
Also we know that session level variables becomes, let we call it๐ , Super Golbal in its scope, due its availabilty through the whole application. i.e all of its pages and parts.
So session_register("var_name") makes the variable $var_name available in any page or any part of the application. That also means if the $var_name is declared and registered as session variable in, for example, page1.php. This variable will be also available in any other page has the session_start() in its begining.
Ok?,
So The standard of Locality bariers(The difference of pages), was broken by registering the variable as a session variable.
Look at the following code:
func.php
<?
function my_func(){
$var_name;
$var_name = "Is it here?"
session_register("var_name");
}
?>
Then look at page1.php
<?
session_start();
include "func.php";
my_func();//so my_func() steps are executed
echo $var_name;//The output is Nothing !!!!??
?>
if we make a modification for the my_func() code as follows,
<?
function my_func(){
global $var_name;
$var_name = "Is it here?"
session_register("var_name");
}
?>
By the above way you can use the session variable and the output will be available on page1.php.
The question is:
Why PHP do without logic like this? it can break the locality of variable among pages, while it can not do like this among function and pages when the variable is registerd as a session variable.?