Skip to content

Commit

Permalink
Merge pull request #421 from calvinbaart/bugfix/allows_null
Browse files Browse the repository at this point in the history
Fix for #416
  • Loading branch information
jakubmisek authored Apr 11, 2019
2 parents ff9ef55 + d819b31 commit b99bb23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Peachpie.Runtime/Dynamic/BinderHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static bool IsImplicitParameter(this ParameterInfo p)
return
p.IsContextParameter() || p.IsQueryValueParameter() ||
p.IsLateStaticParameter() ||
p.IsImportCallerClassParameter() || p.IsImportCallerStaticClassParameter();
p.IsImportCallerClassParameter() || p.IsImportCallerStaticClassParameter() ||
p.IsClosureParameter();

// TODO: classCtx, <this>
}
Expand Down Expand Up @@ -67,6 +68,11 @@ public static bool IsImportCallerStaticClassParameter(this ParameterInfo p)
p.GetCustomAttribute(typeof(ImportCallerStaticClassAttribute)) != null;
}

public static bool IsClosureParameter(this ParameterInfo p)
{
return p.ParameterType == typeof(Closure) && p.Name == "<closure>";
}

/// <summary>
/// Gets value indicating the given type is of type <c>Nullable&lt;T&gt;</c>.
/// </summary>
Expand Down Expand Up @@ -949,6 +955,11 @@ public static Expression BindToCall(Expression instance, MethodBase method, Expr
{
throw new NotSupportedException(); // we don't know current late static bound type
}
else if (p.IsClosureParameter())
{
boundargs[i] = args.BindArgument(argi, p);
argi++;
}
else
{
throw new NotImplementedException();
Expand Down
15 changes: 15 additions & 0 deletions tests/reflection/closure_allows_null_001.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$tmp1 = function (stdClass $user) {
return true;
};

$tmp2 = function (?stdClass $user) {
return true;
};

$param1 = (new ReflectionFunction($tmp1))->getParameters()[0];
$param2 = (new ReflectionFunction($tmp2))->getParameters()[0];

echo $param1->allowsNull() ? "true" : "false";
echo $param2->allowsNull() ? "true" : "false";

0 comments on commit b99bb23

Please # to comment.