RealyUniqueName / haxe

Haxe - The Cross-Platform Toolkit

Home Page:http://haxe.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

optional function parameters

mockey opened this issue · comments

Do you handle optional function parameters in genphp7 or is this handles elsewhere?
There are these auto-generated nulls for missing parameters that are not so good for PHP.

function some (arg:Int = 1) {
}

Translated as

function some ($arg = 1) {
    if ($a === null) {
        $a = 1;
    }
}

So if you call some() Haxe generates expression some(null) and you get expected value $arg = 1 inside of a function.
However there is no way to check whether function was called without arguments or with null as argument.

This is a problem for extern functions where you don't want to pass null quite often.

However there is no way to check whether function was called without arguments or with null as argument.

So the filling with nulls is done somewhere before in the compiler?

This is a problem for extern functions where you don't want to pass null quite often.

We can use externs overloading to avoid passing null for optional arguments: https://github.com/RealyUniqueName/haxe/blob/php7/std/php7/Global.hx#L83

So the filling with nulls is done somewhere before in the compiler?

Yes

We can use externs overloading to avoid passing null for optional arguments

Yes, that's a workaround.

Javascript does not generate null on call for optional parameters.
Why is there issue with php? Why isn't there way?

This is not the case anymore. It was a behavior inherited from old genphp.
There is a per-target config in compiler which i copy-pasted from old genphp. It has that option with null-arguments turned on. I turned it off for new generator and made corresponding changes in 5f296ab

I think, this issue can be closed now. Feel free to reopen if needed.

Can you fix this issue for old genphp too? It will be great!

I tried to build haxe from your source to test, I got this error : "ocamlopt.opt: unknown option `-bin-annot'."
How can I fix that?

Can you fix this issue for old genphp too? It will be great!

I think it was added for purpose, so it might be unsafe to change it.

I tried to build haxe from your source to test, I got this error : "ocamlopt.opt: unknown option `-bin-annot'."

I don't know what is -bin-annot. It's probably something added by core team. Did you try with ocaml 4.0+?

I think it was added for purpose, so it might be unsafe to change it.

That invokes issues for externs. Cannot that be a mistake?

I don't know what is -bin-annot. It's probably something added by core team. Did you try with ocaml 4.0+?

No, I will, thanks

I needed tto install ocaml 4.02 to compile this fork.