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] Improve the generation of anonymous objects declarations #7916

Closed
RealyUniqueName opened this issue Mar 4, 2019 · 3 comments
Closed
Assignees
Labels
platform-php Everything related to PHP

Comments

@RealyUniqueName
Copy link
Member

RealyUniqueName commented Mar 4, 2019

var i = 2;
var o = {hello:1, world:i}

Currently generates

$i = 2;
$o = new HxAnon(["hello" => 1, "world" => $i])

But this performs 50% faster:

$i = 2;
$o = new class($i) extends HxAnon {
  public function __construct(&$i) {
    $this->hello = 1;
    $this->world = $i;
  }
}

PS: don't forget to remove constructor declaration from php.Boot.HxAnon

@RealyUniqueName RealyUniqueName added the platform-php Everything related to PHP label Mar 4, 2019
@RealyUniqueName RealyUniqueName self-assigned this Mar 4, 2019
@nadako
Copy link
Member

nadako commented Mar 4, 2019

does this also support random field adding/deleting? IIRC it has to be supported by anon object values (which is unfortunate).

@Simn
Copy link
Member

Simn commented Mar 4, 2019

Yeah Reflect.deleteField is a real party-pooper...

@RealyUniqueName
Copy link
Member Author

does this also support random field adding/deleting?

Yes adding/deleting fields is supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-php Everything related to PHP
Projects
None yet
Development

No branches or pull requests

3 participants