php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52593 Getting scope variables of the caller function
Submitted: 2010-08-12 14:45 UTC Modified: 2010-08-12 16:06 UTC
From: hpolthof at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.14 OS:
Private report: No CVE-ID: None
 [2010-08-12 14:45 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-12 15:05 UTC] dragoonis@php.net
Please elaborate on "such a function does not exist" with an exact error message.
 [2010-08-12 15:10 UTC] johannes@php.net
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.
 [2010-08-12 15:36 UTC] hpolthof at gmail dot com
Multiple levels are in my opinion not necessary, neighter the way of implementation.

The scope variables could also be made available thru the backtrace() function. And still have no official support.

@dragoonis: I don't know how more specific it can get. get_caller_vars() is a non-existent function. Hence this feature request!
 [2010-08-12 16:06 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2010-08-12 16:06 UTC] derick@php.net
.
 [2010-08-16 02:26 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=302279
Log: Fixed bug #52593 (exif is placed before mbstring in php.ini)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC