diff --git a/src/Peachpie.Library/Reflection/ReflectionUtils.cs b/src/Peachpie.Library/Reflection/ReflectionUtils.cs index 11df12801b..83908131ed 100644 --- a/src/Peachpie.Library/Reflection/ReflectionUtils.cs +++ b/src/Peachpie.Library/Reflection/ReflectionUtils.cs @@ -57,7 +57,7 @@ public static List ResolveReflectionParameters(ReflectionFu { var p = ps[pi]; - var allowsNull = p.GetCustomAttribute() == null; + var allowsNull = p.IsNullable(); var defaultValue = p.HasDefaultValue ? PhpValue.FromClr(p.RawDefaultValue) : default(PhpValue); var isVariadic = p.GetCustomAttribute() != null; diff --git a/src/Peachpie.Runtime/Reflection/ReflectionUtils.cs b/src/Peachpie.Runtime/Reflection/ReflectionUtils.cs index c4aaa58cf7..d16c260d90 100644 --- a/src/Peachpie.Runtime/Reflection/ReflectionUtils.cs +++ b/src/Peachpie.Runtime/Reflection/ReflectionUtils.cs @@ -88,6 +88,31 @@ public static bool IsPhpClassType(TypeInfo tinfo) return !tinfo.IsValueType && t != typeof(PhpArray) && t != typeof(string) && t != typeof(IPhpCallable); } + /// + /// Determines whether given parametr allows NULL as the argument value. + /// + public static bool IsNullable(this ParameterInfo p) + { + if (p.ParameterType.IsValueType && + p.ParameterType != typeof(PhpValue) && + //p.ParameterType != typeof(PhpArray) // TODO: uncomment when PhpArray will be struct + p.ParameterType != typeof(PhpString)) + { + if (p.ParameterType.IsNullable_T(out var _)) + { + return true; + } + + // NULL is not possible on value types + return false; + } + else + { + // NULL is explicitly disallowed? + return p.GetCustomAttribute() == null; + } + } + /// /// Types that we do not expose in reflection. ///