In PHP, this code works:
$usage = (package_manager_get_user_usage($uid));
$usage = $usage[email];
But this does not:
$usage = (package_manager_get_user_usage($uid))[email];
Why? They appear to be doing the same thing.
In PHP, this code works:
$usage = (package_manager_get_user_usage($uid));
$usage = $usage[email];
But this does not:
$usage = (package_manager_get_user_usage($uid))[email];
Why? They appear to be doing the same thing.
That looks like a problem with PHP not being as object-oriented as you perhaps would like. Perhaps (package_manager_get_user_usage($uid))
does not evaluate to the associative array you require to access [email]
on it inline. Some folks marked this as a bug: Bug #24978 PHP should allow access to object properties inline. That link suggests this functionality will be available in PHP5, which leads me to ask: what version of PHP are you using?
If $usage is an array, PHP does not allow you to directly access its elements when it's called. Instead something like this would be more appropriate:
list($usage) = package_manager_get_user_usage($uid);
//Assuming that the first element returned is the one you are trying to access.
And is email defined as some constant in your code? If not, you need to wrap it some quotes.
This question is somewhat related: http://stackoverflow.com/questions/13109/php-access-array-value-on-the-fly
PHP simply has no such syntax like other languages do. In PHP that array-like accessing syntax is only allowed when used together with variables.
This feature was requested but unfortunately it was decliend.