2
0
Эх сурвалжийг харах

[php] Allow passing php class names as strings to `Syntax.instanceof()`

Alexander Kuzmenko 7 жил өмнө
parent
commit
235e8ef8f8

+ 1 - 0
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<Dynamic>, phpClassName:AsVar<String> ) : Bool {})
     static function instanceof<V,C>( value:AsVar<V>,  type:AsVar<Class<C>> ) : Bool;
 
     /**

+ 7 - 0
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 {