I get "Undefine variable" from the following code.
This is all the code from index.php
<?php
include "globals.classes.php";
$anObj = new Globals();
logout();
function logout() {
echo $anObj->getName(); //Warning: Undefined variable $anObj
exit();
}
?>
I know passing $anObj in the parameter will work,
but is it possible to make it work without passing it through parameter?
I want to call a function this way..
logout();
not this...
logout($anObj);
logout($anObj);(besides using classes) is a much more common and recommended way of solving this problem. So I would recommend getting used to it rather than how can I get round it.