mixed call_user_func ( callable $callback [, mixed $parameter [, mixed $... ]] )
call_user_func — Call the callback given by the first parameter
* 사용자가 정의한 함수를 호출하여 실행고자 할 때 사용한다.
* function : 호출할 함수의 이름
* parameter : 호출될 함수를 실행하는 데 필요한 인자
<?php
error_reporting(E_ALL);
function increment(&$var)
{
$var++;
}
$a = 0;
call_user_func('increment', $a);
echo $a."\n";
// You can use this instead
call_user_func_array('increment', array(&$a));
echo $a."\n";
?>
<?php
error_reporting(E_ALL);
function increment(&$var)
{
return 'a';
}
$r = call_user_func('increment', $a);
echo $a."\n";
?>
위와 같이 함수를 실행 후 값을 리턴 받을 수도 있어요
아래 부분은 클래스사용시에요.
<?php
$method_name = "AMethodName";
$obj = new ClassName();
$obj->{$method_name}();
?>
call_user_func 함수 라는 것을 사용하는 것 빼고는
일반적으로 함수 사용하듯이 하면 되요.
단, 클래스일때와 일반 함수일때 잘 구분하셔야 해요.
이런 함수알아두면 코딩 줄 수가 무지 많이 줄일수 있습니다.
게시판 목록
팁게시판
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6077 | 9년 전 | 158 | ||
| 6076 |
PlayPixel
|
9년 전 | 147 | |
| 6075 | 9년 전 | 163 | ||
| 6074 | 9년 전 | 218 | ||
| 6073 |
|
9년 전 | 180 | |
| 6072 |
|
9년 전 | 324 | |
| 6071 | 9년 전 | 228 | ||
| 6070 |
|
9년 전 | 267 | |
| 6069 | 9년 전 | 237 | ||
| 6068 |
|
9년 전 | 189 | |
| 6067 | 9년 전 | 205 | ||
| 6066 |
|
9년 전 | 317 | |
| 6065 |
PASKRAN
|
9년 전 | 212 | |
| 6064 | 9년 전 | 233 | ||
| 6063 |
kiplayer
|
9년 전 | 343 | |
| 6062 |
|
9년 전 | 274 | |
| 6061 | 9년 전 | 216 | ||
| 6060 |
|
9년 전 | 277 | |
| 6059 |
|
9년 전 | 215 | |
| 6058 |
|
9년 전 | 205 | |
| 6057 | 9년 전 | 254 | ||
| 6056 |
|
9년 전 | 207 | |
| 6055 |
|
9년 전 | 254 | |
| 6054 |
|
9년 전 | 231 | |
| 6053 |
snshero
|
9년 전 | 575 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기