Is there really no way of returning an array in a function and dereferencing it in-place?
I'm avoiding littering "global" throughout all functions by using accessor functions, e.g.
$userdata = array(...)
function userdata()
{
global $userdata;
return $userdata;
}
but it's not possible to dereference the function's return, i.e. this doesn't parse:
$username = userdata()["username"];
I've ended up making the array accessor methods also support dereferencing, as below, which also allows for checking that the elements do exist, but it still doesn't really "feel good"...
function userdata($key="")
{
global $userdata;
if (!$key) return $userdata;
if (!isset($userdata[$key])) {
die("userdata: reference to undefined key '$key'\n");
}
return $userdata[$key];
}