I’m trying to use a variable created in local scope without assigning that variable in global. Look what I mean :
<?
function foo(){
$bar = inside;
}
foo();
echo $bar; // It will give an error that $bar is not assigned
?>
Now you may have understood what I’m trying..? Yes I want to echo that $bar without assigning it in global scope.
Some coding examples are well-honored.
Thanks in Advance
Only possibly way is to use the
$GLOBALSsuper-global (at least without returning it):Otherwise you’re looking at defining it in global scope first, then specifying you need access to it using
global:The better alternative is to use objects where scope remains within the object and you can still retain structure and integrity of code: