Skip to content

Commit

Permalink
[php] Allow passing php class names as strings to Syntax.instanceof()
Browse files Browse the repository at this point in the history
  • Loading branch information
RealyUniqueName committed Feb 15, 2018
1 parent 4c1a7a9 commit 235e8ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions std/php/Syntax.hx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ extern class Syntax {
Haxe generates `Std.is(value, Type)` calls as `$value instanceof Type` automatically where possible.
So you may need this only if you have a `Class` stored in a variable.
**/
@:overload(function( value:AsVar<Dynamic>, phpClassName:AsVar<String> ) : Bool {})
static function instanceof<V,C>( value:AsVar<V>, type:AsVar<Class<C>> ) : Bool;

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/src/unit/TestPhp.hx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ class TestPhp extends Test
t(a.indexOf(fn2) < 0);
f(a.remove(fn2));
}

function testSyntaxInstanceof() {
var o = new ClosureDummy();
var phpClassName = Boot.castClass(ClosureDummy).phpClassName;
t(Syntax.instanceof(o, ClosureDummy));
t(Syntax.instanceof(o, phpClassName));
}
}

private class ClosureDummy {
Expand Down

0 comments on commit 235e8ef

Please sign in to comment.