[xdebug-dev] xdebug xdebug/php_xdebug.h xdebug/xdebug.c xdebug/tests/get_declared_vars.phpt - Implemented FR #153: xdebug_get_declared_vars().

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Fri, 30 Dec 2005 16:33:31 +0100

Date: Fri Dec 30 16:33:31 CET 2005
User: Derick Rethans
Directory: xdebug

Log Message:
[1.00]
- Implemented FR #153: xdebug_get_declared_vars().

Modified files:
           xdebug/php_xdebug.h (version: 1.96)
           xdebug/xdebug.c (version: 1.285)
Added files:
           xdebug/tests/get_declared_vars.phpt (new version: 1.1)

[FILE: /xdebug/php_xdebug.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- xdebug/php_xdebug.h:1.95 Wed Oct 05 18:35:37 2005 GMT
+++ xdebug/php_xdebug.h Fri Dec 30 14:33:31 2005 GMT
@@ -58,6 +58,7 @@
 /* call stack functions */
 PHP_FUNCTION(xdebug_get_stack_depth);
 PHP_FUNCTION(xdebug_get_function_stack);
+PHP_FUNCTION(xdebug_get_declared_vars);
 PHP_FUNCTION(xdebug_call_class);
 PHP_FUNCTION(xdebug_call_function);
 PHP_FUNCTION(xdebug_call_file);

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.284
retrieving revision 1.285
diff -u -r1.284 -r1.285
--- xdebug/xdebug.c:1.284 Sun Dec 18 00:04:19 2005 GMT
+++ xdebug/xdebug.c Fri Dec 30 14:33:31 2005 GMT
@@ -125,6 +125,7 @@
 function_entry xdebug_functions[] = {
         PHP_FE(xdebug_get_stack_depth, NULL)
         PHP_FE(xdebug_get_function_stack, NULL)
+ PHP_FE(xdebug_get_declared_vars, NULL)
         PHP_FE(xdebug_call_class, NULL)
         PHP_FE(xdebug_call_function, NULL)
         PHP_FE(xdebug_call_file, NULL)
@@ -1861,6 +1862,40 @@
 }
 /* }}} */
 
+static void attach_used_var_names(void *return_value, xdebug_hash_element *he)
+{
+ char *name = (char*) he->ptr;
+
+ add_next_index_string(return_value, name, 1);
+}
+
+/* {{{ proto array xdebug_get_declared_vars()
+ Returns an array representing the current stack */
+PHP_FUNCTION(xdebug_get_declared_vars)
+{
+ xdebug_llist_element *le;
+ int j;
+
+ array_init(return_value);
+ le = XDEBUG_LLIST_TAIL(XG(stack));
+ le = XDEBUG_LLIST_PREV(le);
+
+ function_stack_entry *i = XDEBUG_LLIST_VALP(le);
+ /* Add declared vars */
+ if (i->used_vars) {
+ xdebug_hash_apply(i->used_vars, (void *) return_value, attach_used_var_names);
+ }
+ /* Add params */
+ if (i->var) {
+ for (j = 0; j < i->varc; j++) {
+ if (i->var[j].name) {
+ add_next_index_string(return_value, i->var[j].name, 1);
+ }
+ }
+ }
+}
+/* }}} */
+
 /* {{{ proto string xdebug_call_class()
    Returns the name of the calling class */
 PHP_FUNCTION(xdebug_call_class)

[FILE: /xdebug/tests/get_declared_vars.phpt]

--TEST--
Test with xdebug_get_declared_vars()
--INI--
xdebug.default_enable=1
xdebug.auto_trace=0
xdebug.collect_params=0
xdebug.auto_profile=0
xdebug.profiler_enable=0
xdebug.dump_globals=0
xdebug.show_local_vars=0
--FILE--
<?php
        function a($a,$b) {
                var_dump(xdebug_get_declared_vars());
        }
        a(52, 52);

        function b($a,$b) {
                echo $a;
                echo $b, "\n";
                var_dump(xdebug_get_declared_vars());
        }
        b(52, 52);

        function c($a,$b) {
                echo $a;
                echo $b, "\n";
                unset($b);
                var_dump(xdebug_get_declared_vars());
        }
        c(3.14, 159);

        function d($a,$b) {
                $c = 3;
                $d = 4;
                echo $a, "\n";
                var_dump(xdebug_get_declared_vars());
        }
        d(1, 2);

        function s()
        {
                $c = 42;
                $d = 54;
                echo $c, $d, "\n";
                var_dump(xdebug_get_declared_vars());
        }

        register_shutdown_function('s');
?>
--EXPECTF--
array(0) {
}
5252
array(2) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
}
3.14159
array(2) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
}
1
array(3) {
  [0]=>
  string(1) "d"
  [1]=>
  string(1) "a"
  [2]=>
  string(1) "c"
}
4254
array(2) {
  [0]=>
  string(1) "d"
  [1]=>
  string(1) "c"
}
Received on Fri Dec 30 2005 - 16:33:32 GMT

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST