assert icon indicating copy to clipboard operation
assert copied to clipboard

nullOr methods do not work with named arguments

Open gubler opened this issue 1 year ago • 0 comments

My team uses named arguments for all arguments if possible. I was using nullOrString and got a 'Missing first argument' error.

After some debugging, I found out that when using the following code:

Assertion::nullOrString(value: $myVar);

What gets passed to __callStatic's $arg parameter is a non-zero indexed array ([value => $myVar]) according to xdebug. Since __callStatic looks for index 0, a 'Missing first argument' exception is thrown.

For now, I can go through and remove the named parameter for all nullOr calls.

I think you could call array_values on the $arg parameter before checking for index 0. This would reindex the array to prevent this error, but I don't konw if that would mess up something somewhere else.

Edit: corrected the index from 1 to value in the array that is passed to __callStatic.

gubler avatar Jan 28 '25 13:01 gubler