dongwen5019 2012-03-05 12:50
浏览 11
已采纳

你可以像php exec一样填充给函数的变量吗?

When using php exec you can pass it with a variable not previously defined like this :

exec('whoami', $result, $status);

and they will be populated with information afterwards or initialized in this function. Can you do something similar with a function inside a custom class?

I have tried to search for an answer but not sure on what to search for so i'm sorry if this has previously been mentioned here.

  • 写回答

1条回答 默认 最新

  • du22399 2012-03-05 12:52
    关注

    You to declare it as a reference:

    function init(&$x) {
      $x = 0;
    }
    $a = 42;
    init($a);
    echo $a; // 0
    

    This behavior is described in the PHP manual. It's the second paragraph of function arguments: Making arguments be passed by reference

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?