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] no arrayAccess in php.NativeStructArray #8893

Closed
mockey opened this issue Oct 24, 2019 · 4 comments
Closed

[php] no arrayAccess in php.NativeStructArray #8893

mockey opened this issue Oct 24, 2019 · 4 comments

Comments

@mockey
Copy link
Contributor

mockey commented Oct 24, 2019

php.NativeStructArray proves really quite useful for defining types of function parameters in extern php functions. Is there any reason why it's missing arrayAccess (opposed to php.nativeAssocArray)?

@RealyUniqueName
Copy link
Member

It is supposed to be used for externs arguments just to provide type safety for options declarations.
Do you have a use case for NativeStructArray in a Haxe code?

@mockey
Copy link
Contributor Author

mockey commented Oct 24, 2019

Yes.
I have an extern function getcliplist which can accept an id or a name.
It's typed like this (simplified):

typedef ClipListRequest = ArrayS<{
  ?id:String,
  ?name:String,
  login:String
}>;
extern public function getcliplist(req:ClipListRequest):ClipListResponse;

Then I like to call it like thiis:

function getClip(id:Int, ?name:String) {
  var req:ClipListRequest = {
    login: "login"
  }
  if (name != null && id == 0) req["name"] = name;
  else req["id"] = id;
  var res = F.getcliplist(req);
}

Adding:

@:arrayAccess
inline function get<V>(key:String):V return this[key];

@:arrayAccess
inline function set<V>(key:String, val:V):V return this[key] = val;

to php.NativeStructArray seems to allow this.

@RealyUniqueName
Copy link
Member

Ideally I'd like to implement a proper typed field access to NativeStructArray. Currently it's blocked by #6639.

@mockey
Copy link
Contributor Author

mockey commented Oct 24, 2019

I see. Thanks for adding it.

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