2

I am learning about Reflection in PHP, and I came across two methods of interest when looking at the parameters of a function: ReflectionParameter::isOptional and ReflectionParameter::isDefaultValueAvailable.

Both methods return boolean values indicating whether the parameter is an optional parameter and whether the parameter has a default value available, respectively.

For the life of me, I can't imagine how these two methods will ever return different values, but the manual at this point gives no indication of this. Can anyone confirm my suspicion, or give an example of a situation in which they would return different values?

3
  • Thank you, and my apologies for inadvertently posting a duplicate! Commented Feb 11, 2018 at 20:41
  • Forgive me, as I can't post a comment on the other post, but I would like some clarification. I understand that function( $foo = 'foor', $bar ) has 0 optional parameters, but is there any way to call this function actually using its default value for the first parameter? calling function(1) assigns 1 to $foo, and calling function(null,1) assigns null to $foo. So we're allowed to put a default value on the first parameter, but we can't actually use it, can we? Commented Feb 11, 2018 at 20:49
  • 1
    To complete Phil answer, you can also consider the case when a ReflectionParameter instance is used on a class property. Example: $reflect = new ReflectionParameter(array('DOMDocument', '__construct'), 'encoding'); Commented Feb 11, 2018 at 20:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.