msgbartop
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

Reader's Comments

  1. |

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

  2. |

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

  3. |

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

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

  4. |

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

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

  5. |

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

  6. |

    $funcs = get_extension_funcs($m);

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

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

  7. |

    php手册:

    Description
    array get_loaded_extensions ( void )

Leave a Comment

*
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