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

Set / get property on object #37

Open
MrAnima opened this issue Oct 24, 2018 · 0 comments
Open

Set / get property on object #37

MrAnima opened this issue Oct 24, 2018 · 0 comments

Comments

@MrAnima
Copy link

MrAnima commented Oct 24, 2018

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 !

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

1 participant