in example some php function return boolean false or integer
how to handle it in haxe?
Here is how it’s handled in std: haxe/Global.hx at 002502d4a67208dc4226b9479e1b1d3e1cbe9ffa · HaxeFoundation/haxe · GitHub
static function substr( string:String, start:Int, ?length:Int ) : EitherType<Bool,String>;
2 Likes
how to check result then?
The fast way is php.Global.is_string()
and is_bool()
methods:
if(php.Global.is_string(result)) {
trace('string');
var str:String = result;
} else {
trace('bool');
var b:Bool = result;
}
The crossplatform way is to use Std.is(result, String)
and Std.is(result, Bool)
.