Press "Enter" to skip to content

寻找函数定义在哪个模块

今天遇到一个问题,需要查看一个函数是定义在哪个模块的, 从而去定位这个模块,翻看其源码。因为我们的环境还不容许使用Reflection APIS, 就直接写脚本了, 没什么大用,就是挺有意思的,;)

get_function_container.php
<?php
$function_name = $argv[1];
$modules = get_loaded_extensions();
foreach($modules as $m){
    $funcs = get_extension_funcs($m);
    if(in_array($function_name, $funcs)){
        printf("%s was defined in Module: %s\n", $function_name, $m);;
        exit;
    }
}
print $function_name ." Must be defined in user defined PHP script files\n";
?>

使用方法:

php -f get_function_container.php  'function_name'

11 Comments

  1. Peggy
    Peggy March 1, 2017

    marijuana for sale on the internet herbal mood elevators euphoric drugs herbal smoke high legal haoinclnlgeus smoke what are the best extacy pills herbal extasy buy k2 or spice buy legal bud. where can i get salvia in florida salvia uliginosa seeds legal natural party drugs spice alternative to cannabis bzp free party pills spike 99 buy where to buy skunk legal where to buy poppers in australia party pills perth. where to buy legal highs in brighton white butterfly extacy legal highs west yorkshire.

  2. lxylxy888666
    lxylxy888666 May 2, 2010

    仅能够找函数,结构语言就找不到,比如echo

  3. Mark long
    Mark long May 20, 2009

    $funcs = get_extension_funcs($m);
    此句会出现非数组的警告,应该改为:
    $funcs = (array)get_extension_funcs($m);

    • laruence
      laruence May 20, 2009

      php手册:
      Description
      array get_loaded_extensions ( void )

  4. Anonymous
    Anonymous October 7, 2008

    ,,,,因为我们的环境还不容许使用Reflection APIS, 就直接写脚本了, 没什么大用,就是挺有意思的,;)

  5. xyz
    xyz October 7, 2008

    C:\>php --rf array_search
    Function [ <internal:standard> function array_search ] {
    – Parameters [3] {
    Parameter #0 [ $needle ]
    Parameter #1 [ $haystack ]
    Parameter #2 [ $strict ]
    }
    }

  6. 雪候鸟
    雪候鸟 September 26, 2008

    哦? 受教了,谢谢,呵呵。

  7. NoAngels
    NoAngels September 26, 2008

    发现这段代码貌似有点问题:因为不是每个module用get_extension_funcs返回的都是数组,所以可以改动代码如下:
    <?php
    $function_name = $argv[1];
    $modules = get_loaded_extensions();
    foreach($modules as $m){
    $funcs = get_extension_funcs($m);
    if (is_array($funcs)){
    if(in_array($function_name, $funcs)){
    printf(“%s was defined in Module: %s\n”, $function_name, $m);;
    exit;
    }
    }
    }

Comments are closed.