Hello! There is a js code:

GgX=((!+[]+!![]+[])+(+[]))+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![])); GgX*=+((+!![]+[])+(+!![])); GgX-=+((+!![]+[])+(!+[]+!![]+!![])); abb = parseInt(GgX, 10)+10; alert(abb); 

22503 - result

Need to rewrite it in php. Tell me:

  1. What kind of "[]" and what this code generally performs, preferably by steps or description of operations.
  2. Analog parseInt in php.
  3. Is there any php script / emulator that allows to execute such javascript code on the server side?

Thank!

  • Everything! The challenge for first-graders is)) I completely remove questions 1 and 2. Question 3 remains relevant - I need advice, I do not want to turn up the php -> nodejs -> php :( - Murky
  • Can you show a solution to the "problem for first graders"? - Angus123

1 answer 1

@Murky , in order to run JavaScript from PHP, you will need to install a corresponding module on the server, for example, v8js .

@ Angus123 , the solution to the “problem for first-graders” will become obvious if we recall that JavaScript is a dynamically typed language, and when you try to perform an action on an object that does not apply to this object, JavaScript will try to bring this object to the appropriate type. In particular, the operation "unary plus" is not applicable to arrays, but it is applicable to numbers. An empty JavaScript array will result in 0, an array with one number will result in this number, an array containing more than one element will result in NaN . Thus, the expression +[] reduced to 0. The logical negation is not applicable to numbers, therefore JavaScript performs the conversion of 0 -> false . Thus, the expression !+[] = true . Similarly !![] = true . Binary addition to Boolean values ​​is not applicable, so they are converted back to numbers !+[]+!![] = true + true = 1 + 1 = 2 . Knowing about such transformations, it is easy to calculate the value of the presented expression.

  • These are the wonders ... I did not know, thank you :) - Angus123