在ecmall中一处见到:
  $this->show_message('edit_ok',
      'back_list', 'index.php?app=my_goods',
      'edit_again', 'index.php?app=my_goods&act=edit&id=' . $id);然后找到这个方法 在 - ecapp.base.php 的 show_message() 的代码如下:
    function show_message()
    {
        $args = func_get_args();
        call_user_func_array('show_message', $args);
    }这个方法中的代码第1行拿到参数, 第2行就又去叫自己(show_message())吗? 
问题1: 使用方法的地方用到了参数, 而这个方法本身是()也就是不接受参数, 他使用func_get_args(); 这是 PHP 的方法重载吗?问题2: 更神奇的是, 这样叫来叫去好像也没干什么事情呀, 但是程序这个时候的确是到了 edit_ok 这个页面, 这段的代码是如何执行的呢? 还叫到其他地方的代码吗?

解决方案 »

  1.   

    $this->show_message(..) //this is a methodfunction show_message(){..} //this is a function
    //are you sure the function in the class , or the class in the ecapp.base.php ?
      

  2.   

    从楼主发的两个帖子,建议你好好去看看PHP的OOP,这样子才能从根本上解决你的疑惑。
      

  3.   

    coolesting: if i am perfectly sure, why even bother dropping some dumb questions here?! eclipse's f3 brings me there, so the answer is uncertainruanchao, 没错, PHP 的 OOP 和以前遇到的OOP很不一样, 这就是我的疑惑, 按F3得到的东西我不确定是否正确, 其实如果这个问题能明白, 我的PHP就涨了一大步了, 谢谢啊老兄, 你的上一个答案给了我很多启发, 我接触PHP就2周, 单单搞PHP还好, 但是加上ecmall这样的开源框架, 读起来真的有许多困惑, 因为PHP的底子很薄, 原理肯定没那么好摸的, 一定要总结了许多这样的小问题才行啊, 不过ecmall写的是挺有水平的, 越搞越觉得有水平
      

  4.   

    >> PHP 的 OOP 和以前遇到的OOP很不一样
    可能不能这么说, 应该是语法或写法很不一样, 因为PHP感觉写起来非常活, 因为是解释型的语言, 反正拼成了对的语句就能跑, 所以还不太适应
      

  5.   

    两周?然后找到这个方法 在 - ecapp.base.php 的 show_message() 的代码如下:
    function show_message()
    {
    $args = func_get_args();
    call_user_func_array('show_message', $args);
    }请查找一下func_get_args()和call_user_func_array()两个函数的用法
    这个show_message()函数最终是eccore/controller/messages.base.php文件中定义的
      

  6.   

    look down ...<?php
    function test()
    {
        $arg_list = func_get_args();
        foreach($arg_list as $_key => $_value){
            echo "Argument $_key is: " . $_value . "<br />\n";
        }
    }test(0,1,2,3);    //output all of argument.//so ...
    function show_message()
    {
        $args = func_get_args();
        //now, look here , the functoin that could be auto set the argument.
        call_user_func_array('show_message', $args);
    }
    ?>
      

  7.   

    ruanchao:function show_message ($msg)
    {
        $a = _trigger_message(func_get_args());    _message(serialize($a), E_USER_NOTICE);
    }谢谢啊! ecmall本身代码多, 经常跳来跳去, 一会儿就不知道跳到哪里去了, 很想请教一下, 你怎么看出来的呀, 上下文没有提示, F3有时也是错误的定位, 虽然哪边可能有一个 require, 就把 eccore/controller/messages.base.php 包含了, 但是代码还是很多呀, 这个快速地定位全是靠经验还是有点小窍门呀, 和大家分享一下嘛, 嘻嘻down is often used for oral by the way, try to use the word - below, i.e. check the code below, dont make me to correct your writings, iam evil :P
      

  8.   

    如果精力充足和而且走读代码能力比较好的话,可以很快地定位,否则只有ecmall的开发人员才知道的吧,呵呵。一边看代码,一边借助于工具查找,我并没有很快的定位。
      

  9.   


    其实coolesting是告诉你如何去读代码并定位,方法非常好我之前有参与过一个ecmall项目的二次开发,代码大概走读过,所以可能会比刚接触的同学稍微快一些
      

  10.   

    我还是没有找到call_user_func_array的用法。