PHP : ReflectionParameter, isOptional vs isDefaultValueAvailable

前端 未结 2 1447
予麋鹿
予麋鹿 2020-12-15 11:57

What is the difference between two. both of these are working exactly in a same way.

public static function getArgsArray($reflectionMethod,$argArray){
    $a         


        
2条回答
  •  自闭症患者
    2020-12-15 12:45

    Good question. Consider this example

    function foo($foo = 'foo', $bar) {}
    

    For the $foo parameter, isDefaultValueAvailable() would understandably return true however isOptional() would return false as the next parameter ($bar) has no default value and is therefore not optional. To support the non-optional $bar parameter, $foo must itself be non-optional.

    Hope this makes sense ;)

    I've noted that behaviour differs across PHP versions. 5.5 returns the above whereas 5.4 says parameter 1 is both not optional and has no default value.

    • PHP 5.4 - https://eval.in/154641
    • PHP 5.5 - https://eval.in/154642

提交回复
热议问题