Desmond Hume
Desmond Hume

Reputation: 8607

"Warning: func_get_arg(): Argument ... not passed to function in ..."

Why does the following code produce "Warning: func_get_arg(): Argument 1 not passed to function in /t.php(6) : assert code on line 1"?

function func($param0/*, ...*/)
{
    assert('is_string(func_get_arg(0))'); // ok
    assert('is_string(func_get_arg(1))'); // error
}
func("param0", "param1");

Codepad: http://codepad.org/5G9kMWKJ

Upvotes: 0

Views: 1966

Answers (2)

Dejay Clayton
Dejay Clayton

Reputation: 3878

Per this insightful comment on PHP's page for assert:

Note that func_get_args() should be used carefully [in assert] and never in a string! ... This is because of that the string passed to assert() is being evaled inside assert, and not your function.

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

My guess would be because the func_get_arg is referring to the assert call, NOT to the func.

Demo of it working with var_dump: http://codepad.org/37uDiSDy

Upvotes: 2

Related Questions