php.js
php.js copied to clipboard
Operator Overloading
There may be a problem with operator overloading behavior in the library.
Take:
Both $a + $b and $b + $a will cause a fatal error of unsupported operand types in PHP. However, in JS neither case is true. They yield unexpected results in JS, actually as {} + [] and [] + {} result in 0 (or NaN depending on the engine), and "[object Object]", respectively. Here the code above results in:
int(0) int(0)
Which is what I expect the library VM is doing with the operator ADD here.
Seems like a bug indeed, which most likely is also present in minus, div, multiply and mod operators as well then, will have a closer look at this later