When we include a PHP script inside a PHP file the variables declared in the included PHP script are accessible in the PHP file that includes that PHP script.
Those variables can be assigned a different value in the calling PHP script. How to prevent it?
Please, see these two example PHP files:
global.php
Code: Select all
<?php
$currency = "Rs.";
$line = str_repeat("_",80);
?>include.php
Code: Select all
<?php
include("global.php");
echo $currency;
echo $line;
$line = "NO LINE";
echo $line;
?>Code: Select all
Rs.________________________________________________________________________________NO LINE
The variable $line is being assigned a new value in the second PHP file. How to prevent it?