I need some PHP code to convert some PHP into JS.

* functionality - I'm using common PHP functions from [php.js](http://phpjs.org/)
* syntax - ???

The issue is converting the syntax. I don't need full PHP syntax, mind you; no need for supporting class definitions/declarations. Here's a small checklist of what needs conversion:

* "." should be "+" (string concat)
* "->" should be "." (object operator)
* "::" should be "." (class operator - not really required)

Please note that the resulting code is pretty much independent of the PHP environment, so no "what if it uses a PHP class?".

I'm not asking for full code, just a tip on the right direction to this kind of conversion; I was thinking about employing a state machine/engine.

If you're curious as to why I'm pushing code to the user side: I need a dynamic way to change visibility of certain elements given certain conditions. My plan is to do this without having to execute this code server side and having unnecessary ajax calls.

**Edit:** Look people. I know not using AJAX sounds ludicrous to you but the world doesn't work on hype and nice-sounding design conditions (=ajax). I simply can't afford each single user polling my server 5 to 10 times per second just for my server to return a "yes" or "no" answer. Keep in mind that switching is asynchronous, and I can't buffer the AJAX calls.

**Edit 2:** I am sure what I'm doing is the best way in my situation. There is no "possibly better" way, so quit posting non-constructive comments. I can't get into any more detail than I have so already. The conversion from PHP code to JS is simply a matter of shortening user input; we only need one expression, then convert it to whichever language is necessary (in this particular case, from PHP to JS). The conditions on how this works will *not change* regardless if I describe the system down to the API specs, and inundating the topic with useless (for you) prototype docs will not help at all.

Also, for those thinking this idea came after waking up form some dream; know this has been reviewed between technical development and QA, so please do not deviate into inexistent design issues.

**Edit 3:** Examples (original PHP code and expected output):

* (original) -- (converted)
* `5=="test"` -- `5=="test"`
* `'$'.(func(12)*10)` -- `'$'+(func(12)*10)`
* `Fields::count()==5` -- `Fields.count()==5`
* `$this->id==5` -- `this.id==5`

About the last example, don't worry about context/scope, it is correct. Also note that the expressions may look weird; this is because they *are* expression; a single line of code that must return a value, which explains the absence of an EOL (;) and the multiple use of returning a boolean value. (exotic stuff like backtick operator execution, PHP tags, echo, die, list, etc.. left out on purpose)