【PHP】unset関数とスコープ
ユーザー定義関数内で引数をunsetした場合、その引数が参照渡しされていたとしても破棄されるのは引数のみで参照元には影響しない。
<?php function myFunc(&$num){ echo $num; //1 $num++; unset($num); echo $num; //null } $num = 1; myFunc($num); echo $num; //2 ?>
ユーザー定義関数内で引数をunsetした場合、その引数が参照渡しされていたとしても破棄されるのは引数のみで参照元には影響しない。
<?php function myFunc(&$num){ echo $num; //1 $num++; unset($num); echo $num; //null } $num = 1; myFunc($num); echo $num; //2 ?>