Variable scope (as defined here)
The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope. This single scope spans included and required files as well.
//a.php
<?php
class a {
function &func () {
$avar = array("one", "two", "three");
return $avar;
}
?>
__
//b.php
<?php
class b {
include("a.php");
$ainstance = new a;
var_dump($ainstance->func());
}
?>
The above code will Dump information about the variable as expected (I mean WRT the structure as formed in the function func).
My doubt is that,
- where are the variable stored when it is in the scope of a function?
- If it is on the call stack, then wont the variable be cleaned/destroyed when the function terminates?
- Since the variable is not getting destroyed (as per the code above), why is it not getting destroyed or does PHP have a mechanism to save the variable (say in a heap)and return the reference to it.
- Does PHP have call stack at all?