php.js icon indicating copy to clipboard operation
php.js copied to clipboard

Operator Overloading

Open srgoogleguy opened this issue 13 years ago • 1 comments

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.

srgoogleguy avatar Jul 25 '12 05:07 srgoogleguy

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

niklasvh avatar Jul 25 '12 12:07 niklasvh