Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP] Would it be possible to allow inlined vars with untyped code? #4770

Closed
mockey opened this issue Jan 6, 2016 · 4 comments
Closed

[PHP] Would it be possible to allow inlined vars with untyped code? #4770

mockey opened this issue Jan 6, 2016 · 4 comments
Milestone

Comments

@mockey
Copy link
Contributor

mockey commented Jan 6, 2016

It would be quite nice if something like this was allowed for dealing with PHP constants:
public static inline var phpVersion:String = untyped __php__("PHP_VERSION");

Right now you have to do:

public static var phpVersion(get,never):String;
static inline function get_phpVersion() return untyped __php__("PHP_VERSION");

which is OK, but doesn't work in @:enum abstract e.g.:

@:enum abstract SoapVersion(Int) {
  var SOAP_1_1 = untyped __php__("SOAP_1_1");
  var SOAP_1_2 = untyped __php__("SOAP_1_2");
}

You have to lookup the actual integer vaalues there.

@Simn
Copy link
Member

Simn commented Jan 6, 2016

I'm not sure if that's feasible with the current representation of native code. This is treated like a call which is not a constant expression, which generally makes sense. I have multiple issues with these constructs and would like to see it change, but I'm not quite sure how to go on about it.

@Simn Simn modified the milestone: 3.3.0-rc1 Feb 23, 2016
@mockey
Copy link
Contributor Author

mockey commented Mar 6, 2016

There's no way to trick the compiler into treating this as a constant somehow with a macro, is there?

@Simn
Copy link
Member

Simn commented Mar 23, 2016

Unfortunately I see now way to support this without making internal structural changes. We can look at it again for Haxe 4 (#4684), but for the time being I might as well close the issue. Sorry!

@Simn Simn closed this as completed Mar 23, 2016
@mockey
Copy link
Contributor Author

mockey commented Mar 23, 2016

Note that this was only supposed to be a workaround for using global PHP constants. Since #4925 the example above can be written as:

@:native("")
@:phpConstants
@:enum extern abstract SoapVersion(Int) {
  var SOAP_1_1;
  var SOAP_1_2;
}

A bit verbose maybe, but works. No untyped __php__ needed, which is some improvement at least. The only problem left is that the compiler refuses to see this as a real constant. So maybe adding a value to TConstant for that could be considered, like TExtern?

Also externs for global functions can be defined in a similar way now, which eliminates the need for untyped __call__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants