title: PHP code to convert PHP to JS
body: <p>I need some PHP code to convert some PHP into JS.</p>
  
  <ul>
  <li>functionality - I'm using common PHP functions from <a href="http://phpjs.org/" rel="nofollow noreferrer">php.js</a></li>
  <li>syntax - ???</li>
  </ul>
  
  <p>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:</p>
  
  <ul>
  <li>"." should be "+" (string concat)</li>
  <li>"->" should be "." (object operator)</li>
  <li>"::" should be "." (class operator - not really required)</li>
  </ul>
  
  <p>Please note that the resulting code is pretty much independent of the PHP environment, so no "what if it uses a PHP class?".</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><strong>Edit:</strong> 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.</p>
  
  <p><strong>Edit 2:</strong> 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 <em>not change</em> 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.</p>
  
  <p>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.</p>
  
  <p><strong>Edit 3:</strong> Examples (original PHP code and expected output):</p>
  
  <ul>
  <li>(original)  --  (converted)</li>
  <li><code>5=="test"</code>  --  <code>5=="test"</code></li>
  <li><code>'$'.(func(12)*10)</code>  --  <code>'$'+(func(12)*10)</code></li>
  <li><code>Fields::count()==5</code>  --  <code>Fields.count()==5</code></li>
  <li><code>$this-&gt;id==5</code>  --  <code>this.id==5</code></li>
  </ul>
  
  <p>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 <em>are</em> 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)</p>