2011-02-12 2 views
9

PHP 매뉴얼을 보았습니다. 그러나 이전 버전과 이후 버전의 PHP 간의 동작 차이는 이해할 수 없습니다. 그것은이 5.2에 유효하다는 것을 의미PHP 5.2에서 5.3까지 func_num_args, func_get_arg 및 func_get_args의 동작 차이점

Because this function depends on the current scope to determine parameter details, it cannot be used as a function parameter in versions prior to 5.3.0. If this value must be passed, the results should be assigned to a variable, and that variable should be passed.

답변

11

이러한 함수 중 하나의 결과를 다른 함수 나 메서드에 전달하려면 5.3 이전의 PHP 버전에서 먼저 결과를 변수에 할당해야했습니다.

function some_func() { 
    $args = func_get_args(); 
    some_other_func($args); 
} 

이 제한 사항은 PHP 5.3에서 제거되었으며 이제 결과를 직접 전달할 수 있습니다.

이 제한은 처음부터 존재 이유에
function some_func() { 
    some_other_func(func_get_args()); 
} 

, PHP의 내부의보다 철저한 이해와 아마 누군가가 당신에게 더 완전한 대답을 줄 수 있습니다.

+0

아마도 PHP가 호출하는 함수의 범위와 전달되는 함수 사이에서 혼란 스러울 수 있습니다. – BoltClock

+0

정말 이상한 시나리오에서도 제대로 작동하는 것으로 보입니다. http://codepad.org/MQkQnnJH – cmbuckley

8

: 나는이 문장을 이해하지 못하는

function foo() { 
    $array = array_map('strtolower', func_get_args()); 
} 
foo('BAR', 'BAZ'); 

그것은 치명적인 오류로 중단됩니다 : 5.3 그러나

PHP Fatal error: func_get_args(): Can't be used as a function parameter

을, 그것은 유효한 코드입니다.

+0

Googlable 오류 메시지의 경우 +1 – Daniel