endel/js2php

Set / get property on object

MrAnima opened this issue · 0 comments

Given the following JS code:

let a = {};
a.foo = 123;
var_dump(a.foo);

js2php transpiles it to:

$a = array();
$a->foo = 123;
var_dump($a->foo);

But the PHP code doesn't work because we cannot set arbitrary variables on object (this is also the case for class instances, let's say you had let a = new MyClass()). Because this is a major difference between the two languages, I doubt it will be easy to fix. I think that the best thing that can be done would be to override __set and __get and keep a private $properties = array() inside each class.
Anyways, I just discovered your project and it looks really interesting, I'll stay updated !