RealyUniqueName / haxe

Haxe - The Cross-Platform Toolkit

Home Page:http://haxe.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@:phpGlobal for externs for global functions

mockey opened this issue · comments

How about it?
E.g. take all the functions from here:
http://php.net/manual/en/ref.var.php
and stuff them into:

@:phpGlobal extern class Var {
  static function is_array(o:Dynamic):Bool;
  ...
}

And then write Var.is_array(arr) instead of untyped __call__("is_array", arr), but with completion and type-check.

I'm not sure if all of them should be in public classes. It can be really helpful for haxe->php dev, but how much do you use untyped __call__ as haxe->php user?

I'm not sure if all of them should be in public classes.

That's a general decision, how much of the native PHP API you want to expose. It was just an idea, the global functions are there, they are sorted in a way and they are documented, why not generate externs to some of them at least.

It can be really helpful for haxe->php dev, but how much do you use untyped call as haxe->php user?

Depends on the use case. I use quite a lot native PHP classes (SoapClient e.g.) or functions (pspell, apcu, e.g.), and I already wrote externs for them.

But of course you could also pick certain important functions and stuff them in an extern class. Still some @:phpGlobal metadata that simply avoids generating Class:: for extern static functions might be useful.

Implemented in dd7cebd.

If extern class has @:phpGlobal meta then static methods translated to global functions and static vars translated to global constants. (see commit for examples)

Cool.
But I think the name for Const is not ideal in the long run. Why not ErrorConstant?
Also constants like this could be implemented as abstract enums, see my comment:
#12 (comment)
Not sure if this is a big advantage, though. Pattern matching maybe...

Think about current Global and Const as temporary externs for development purposes )

I will :-)