PHP Global Variable
name: initial vj name: vj name: vj name in file2: vj
Code:
<?php
$name ;
$name ='initial vj';
echo '<br/>name: ' .$name;
test($name);
function test(&$name)
{
$name = 'vj';
echo '<br/>name: ' .$name;
}
echo '<br/>name: ' .$name;
include('file2.php');
?>
<?php
$name;
echo '<br />name in file2: ' .$name;
?>
This concept is called "application scope." PHP is better equipped for a scope of session, request or page. To place data within application scope in PHP, it's more common to make a database call to get the value.
We can use superglobals like $_SESSION, $_REQUEST or $_POST and $_GET to assign the variable to live beyond just one page, inside the session, request or page scopes. PHP doesn't have a common, similar method for assigning a value to a variable in application scope. Instead, application scopes are often imitated by calling an outside source of data, like a database or file. Earlier versions of PHP had some features that leaned toward the concept of application scope, but they have been deprecated.
For your questions:
Instead of doing this for all users by one user, we often write this kind of code as a $_SESSION variable, usable by one user at a time. It is common for us to use a database write and a database read to solve this kind of problem. Simply put down the value by the user who writes it. Get it for the readers.
There is a super-global named $GLOBALS, but it is more of a shortcut for annotating how a variable is named. It's not a feature that will bring application scope to the variable.
JSP allows the use of application scoped variables by simple declaration. ASP allows the use of application scoped variables through application configuration with XML. PHP doesn't directly use application scope in the context of a variable, object or class.
php man scope php man reserved