This is probably a simple question, and I'm afraid the answer might be "no", but...
Here's a simple piece of code:
function func1() {
$bt = debug_backtrace();
print "Previous function was " . $bt[1]['function'] . "\n";
}
Now... Can this be done without the temporary variable? In another language, I might expect to be able to say:
function func1() {
print "Previous function was " . (debug_backtrace())[1]['function'] . "\n";
}
Alas, in PHP, this results in an error:
PHP Parse error: syntax error, unexpected '[' ...
If it can't be done, it can't be done, and I'll use a temporary variable, but I'd rather not.
No, direct dereferencing is unfortunately not supported in current versions of PHP, but will apparently come in PHP 5.4.
Also see Terminology question on "dereferencing"?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With