Language is PHP 5.4 on an Apache 2.2 server. It’s a script being called by ajax.
$usr = new User();
function getMyName(){
echo $usr->username;
}
getMyName();
For some reason $name is out of scope. Why would that be the case? I also tried directly calling the script with the same result. I tried use($name) to resolve, but that apparently only works with anonymous functions (closures)?
When I do this, it works but it’s ridiculous:
$usr = new User();
$name = $usr->username;
function getMyName($n){
echo $n;
}
getMyName($name);
alternatively: