From 235e8ef8f82969495037e55ad06f409e52dc8106 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Thu, 15 Feb 2018 12:11:15 +0300 Subject: [PATCH] [php] Allow passing php class names as strings to `Syntax.instanceof()` --- std/php/Syntax.hx | 1 + tests/unit/src/unit/TestPhp.hx | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/std/php/Syntax.hx b/std/php/Syntax.hx index 46c920b3f5d..a16eeea2529 100644 --- a/std/php/Syntax.hx +++ b/std/php/Syntax.hx @@ -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, phpClassName:AsVar ) : Bool {}) static function instanceof( value:AsVar, type:AsVar> ) : Bool; /** diff --git a/tests/unit/src/unit/TestPhp.hx b/tests/unit/src/unit/TestPhp.hx index 889a40dd1da..d9cfee8fda5 100644 --- a/tests/unit/src/unit/TestPhp.hx +++ b/tests/unit/src/unit/TestPhp.hx @@ -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 {