msgbartop
PHP应用,PHP源码分析,Zend引擎分析,Web相关技术研究,Web技术分享 – 左手代码 右手诗
msgbarbottom

22 Aug 08 寻找函数定义在哪个模块

今天遇到一个问题,需要查看一个函数是定义在哪个模块的, 从而去定位这个模块,翻看其源码。因为我们的环境还不容许使用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'

Related Posts:

  • No Related Post

8 Responses to “寻找函数定义在哪个模块”

  1. lxylxy888666 |

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

  2. laruence |

    php手册:

    Description
    array get_loaded_extensions ( void )

  3. Mark long |

    $funcs = get_extension_funcs($m);

    此句会出现非数组的警告,应该改为:

    $funcs = (array)get_extension_funcs($m);

  4. Anonymous |

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

  5. xyz |

    C:\>php --rf array_search
    Function [ <internal:standard> function array_search ] {

    – Parameters [3] {
    Parameter #0 [ $needle ]
    Parameter #1 [ $haystack ]
    Parameter #2 [ $strict ]
    }
    }

  6. xyz |

    C:\>php –rf array_search
    Function [ function array_search ] {

    – Parameters [3] {
    Parameter #0 [ $needle ]
    Parameter #1 [ $haystack ]
    Parameter #2 [ $strict ]
    }
    }

  7. 雪候鸟 |

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

  8. NoAngels |

    发现这段代码貌似有点问题:因为不是每个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;
    }
    }
    }

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word