auto scroll after unlinking port
[racktables-contribs] / function-analysis.php
1 #!/usr/bin/php
2 <?php
3
4 # This script outputs a list of functions that are used in local.php
5 # file, but don't belong to it. It requires a working php-pecl-parsekit
6 # package installation.
7
8 function get_all_function_calls ($tree)
9 {
10 $self = __FUNCTION__;
11 $ret = array();
12 if (array_key_exists ('opcodes', $tree))
13 foreach ($tree['opcodes'] as $item)
14 switch ($item['opcode'])
15 {
16 case 59: // ZEND_INIT_FCALL_BY_NAME
17 $ret[] = $item['op2']['constant'];
18 break;
19 case 60: // ZEND_DO_FCALL
20 $ret[] = $item['op1']['constant'];
21 break;
22 default:
23 break;
24 }
25 if (array_key_exists ('function_table', $tree))
26 foreach ($tree['function_table'] as $item)
27 $ret = array_merge ($ret, $self ($item));
28 return $ret;
29 }
30
31 function get_locally_declared_functions ($tree)
32 {
33 $self = __FUNCTION__;
34 $ret = array();
35 if (array_key_exists ('function_table', $tree))
36 foreach ($tree['function_table'] as $funcname => $item)
37 $ret = array_merge ($ret, array ($funcname), $self ($item));
38 return $ret;
39 }
40
41 function get_foreign_function_calls ($tree)
42 {
43 $ret = array();
44 $localnames = get_locally_declared_functions ($tree);
45 foreach (array_unique (get_all_function_calls ($tree)) as $func_call)
46 if (! in_array ($func_call, $localnames) and ! function_exists ($func_call))
47 $ret[] = $func_call;
48 return $ret;
49 }
50
51 $tree = parsekit_compile_file ('local.php');
52 print_r (get_foreign_function_calls ($tree));
53
54 ?>