开发者

Difference in behaviour of func_num_args,func_get_arg and func_get_args from php 5.2 to 5.3

开发者 https://www.devze.com 2023-02-10 16:25 出处:网络
I have seen the PHP manual. But I don\'t understand the dif开发者_StackOverflow社区ference in behaviour between the earlier version and the later versions of PHP. I don\'t understand this statement:

I have seen the PHP manual. But I don't understand the dif开发者_StackOverflow社区ference in behaviour between the earlier version and the later versions of PHP. I don't understand this statement:

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.


If you wanted to pass the result of one of those functions to another function or a method, in versions of PHP prior to 5.3 you had to first assign the result to a variable.

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

This limitation was removed in PHP 5.3 and you can now pass the result directly.

function some_func() {
    some_other_func(func_get_args());
}

As to why this limitation existed in the first place, perhaps someone with a more thorough understanding of PHP's internals can give you a more complete answer.


It means that this is invalid in 5.2:

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

It will abort with a Fatal error:

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

However in 5.3, it is valid code.

0

精彩评论

暂无评论...
验证码 换一张
取 消