npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

phpvm

v0.0.4

Published

PHP to JavaScript converter and VM written in JavaScript

Downloads

14

Readme

php.js

PHP VM in JavaScript

This library reads PHP code and transforms it into JavaScript code which can be run in the PHP VM in this library, resulting in same results as with PHP. It starts by tokenizing the PHP code into tokens, which it then uses to build an AST tree. Once the tree has been constructed, the script compiles it into JavaScript that can be interpreted by the VM and then executes it. Any additional unconverted code that gets executed within the VM, such as eval or lambda functions will go through the same process before being executed.

The code can be directly run in your browser, meaning you can execute php code straight out of your browser! It can also be run on node.js, but strongly recommend not to, due to potential security issues.

Some examples

  • Magic methods (2, 3)
  • ArrayAccess
  • Lamba functions
  • Engine execution orders (2,3)
  • foreach with references
  • tokenizer

Usage

var engine = new PHP ('<?php echo "Hello world!"; ?>', options);
console.log(engine.vm.OUTPUT_BUFFER); // the outputted buffer from the script

The code is by default run synchronously so the output will be immidiately readable upon the engine finishing execution. Alternatively, the VM can be set to run under a web worker as well, in which case a callback function will need to be provided.

Status

This project was purely for my personal learning. If it isn't obvious, this shouldn't be incorporated in any type of application, and the only reason it is open source is that if someone would find useful information or parts from it. I took a test driven approach to developing this library, which means that I have been mostly focusing on getting the php unit tests (which PHP uses itself) to work correctly. If a certain functionality hasn't been a part of the base unit tests (around 670 in total), it most likely won't work or only works partially. Additionally, only a fraction of module functions have been implemented, and even for the ones that have been, many of them are only partially implemented (i.e. signature checks haven't really been implemented to any functions, although user created functions support them). However, additional functions can easily be added, as they can be written in PHP and have them compiled into JavaScript.

The current status of the passing tests can be seen here. I'll be the first admit that there are still a lot of bugs, but considering the complexity of the language, it is well on its way.

Building

npm install
grunt 

License

JavaScript code licensed under MIT license PHP Files and tests under The PHP License, version 3.01

Credits

  • Test cases from php-src - The PHP License, version 3.01
  • Grammar parser adapted from PHP-Parser - by Nikita Popov

Questions & Comments

If you encounter a bug, please feel free to post it on GitHub. For questions or comments, you can contact me at Twitter @niklasvh or Google Plus