Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phpengine/5ad90bc2f2630cbc7548e85171f3b6a3 to your computer and use it in GitHub Desktop.
Save phpengine/5ad90bc2f2630cbc7548e85171f3b6a3 to your computer and use it in GitHub Desktop.
Replacing Javascript with PHP in Browser
# ZendCon CFP: Replacing Javascript code with PHP in Browser
## Also, I'll need to send it in by the 14th of April - thanks
## Motivation: Why do we care about the problem and the results?
We are all PHP Developers. Javascript is a dependency, that most PHP
developers
## Problem statement: What problem are you trying to solve?
Historically, PHP has sat hand in with Javascript. PHP Logic Back
End, Javascript Logic Front End. The main reason for
this being, that we are in control of our servers and can install PHP
on them. The Javascript engine is the only one that runs in browsers
currently. Now, we have a platform that means we can go a large way
to deprecating Javascript syntax, while we still have access to the
all of the benefits. Libraries such as jQuery for Instance, we just
access it like it was a PHP Class, using code run in a browser.
Approach: How did you go about solving or making progress on the
problem? Did you use simulation, analytic models, prototype construction,
or analysis of field data for an actual product?
The principle behind making this work is called Abstract Syntax Tree
compilation (or Transpilation), and the framework that provides this
for us from PHP to Javascript is called Uniter PHP. Other big
interpreted languages, (primarily Ruby and Python) also have
implementations of this, namely PyJS for Python and RubyJS and OpalRB
for Ruby. RubyJS carry the quote on their home page (From the creator
of Ruby ):
" If I had to code JavaScript I would use RubyJS. "
Yukihiro (Matz) Matsumoto, creator of Ruby
## Results: What's the answer?
Now this exists for PHP too, in the form of a project called Uniter.
Uniter will run PHP Logic in a browser, and does it well. Uniter
comporises multiple components in both Node and PHP, to bring a complete
package allowing any PHP Developer to use PHP instead of Javascript
in the Javascript engine.
## Conclusions: What are the implications of your answer? Is it going to
change the world (unlikely), be a significant "win", be a nice hack,
or simply serve as a road sign indicating that this path is a waste of
time (all of the previous results are useful)?
This opens the door for PHP Front End Frameworks, Isomorphic Frameworks,
PHP Single Page Apps with no PHP Back end, and much more. All of the
types and designs of Applications that you may have come across in
Node and Javascript over the last few years. Think React PHP, Meteor
PHP, Angular PHP, Derby PHP. Also think Zend Framework for Browser,
Symfony for Browser, etcetera.
We have lots of working examples too...
[Uniter JQuery](http://www.uniterjquery.org.uk) - Examples of common
tasks performed by Web Developers using jQuery, written in PHP executed
in browser.
[The Uniter League](http://www.theuniterleague.org.uk) - A collection
of Applications and Web Sites written using Uniter PHP.
[Front End PHP](http://www.fephp.org.uk) - Here's what I think
is the first library of code written in PHP specifically for the browser.
It's new and still quite small so far. It currently includes replacements
for the default alert and confirm dialogue boxes that you find in every
browser, and adds overlays too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment