Req #52593 [Opn]: Getting scope variables of the caller function
Edit report at http://bugs.php.net/bug.php?id=52593&edit=1
ID: 52593
Updated by: johannes@php.net
Reported by: hpolthof at gmail dot com
Summary: Getting scope variables of the caller function
Status: Open
Type: Feature/Change Request
Package: *General Issues
PHP Version: 5.2.14
Block user comment: N
New Comment:
Then you also need get_callers_caller_vars() and
get_callers_callers_caller_vars() but by definition a function shall be
independent from the caller's scope. All required information shall be
passed as parameter.
Previous Comments:
------------------------------------------------------------------------
[2010-08-12 15:05:21] dragoonis@php.net
Please elaborate on "such a function does not exist" with an exact error
message.
------------------------------------------------------------------------
[2010-08-12 14:45:51] hpolthof at gmail dot com
Description:
------------
In bug #48290 was the function get_caller_vars() suggested. But in that
case it was irrelevant. However do I seek such a function.
get_defined_vars() returns the vars in the current scope. As do i like
to get the variables of the caller routine.
This would allow me to use parameters from a subroutine without having
to refactor another parameter being get_defined_vars() as this would
obviously uglify my code, which would impeach the reason to refactor in
the first place.
Test script:
---------------
function a() {
$test = 'A';
b();
}
function b() {
$test = 'B';
$vars_local = get_defined_vars();
$vars_caller = get_caller_vars();
echo $vars_caller['test']; // Expexted: A
echo $vars_local['test']; // Expected: B
}
a();
Expected result:
----------------
A
B
Actual result:
--------------
such a function does not exist
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52593&edit=1
Thread (5 messages)