LoginSignup
3

More than 5 years have passed since last update.

func_get_args()は値渡しになる

Last updated at Posted at 2012-04-18

仕様らしい。

<?php
function testRef(&$a) {
  $args = func_get_args();
  $args[0] = 1;
}

testRef($a);
var_dump($a); //->null

func_get_arg()を使うと、あらかじめ参照渡し宣言がされている引数については参照で受け取り、それ以外は値渡しになります。

<?php
function testRef(&$a) {
  $arg1 = func_get_arg(0);
  $arg1 = 2;
}

testRef($b);
var_dump($b); //->2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3