<?php
// This is a PHP program that tests local scope
function testScope() {
$localVar = "Hello, World!"; // A local variable inside the function
echo $localVar; // Print the value of the local variable
}
testScope(); // Call the function to test the local variable
// Try to access the local variable outside the function
// This will generate a "Undefined variable" error because the variable is only defined inside the function
echo $localVar;
?>
Hello, World!
testScope()
` is defined, and inside the function, a local variable called `$localVar
` is declared and assigned the value "Hello, World!". The value of the local variable is then printed to the screen using the `echo
` command.