JavaScript for PHP developers

If you’re a PHP developer and you find it difficult to get used to all the insides of JavaScript, I think you need to take a look at PHP.JS. It’s a brilliant tool initially developed by Kevin van Zonneveld, and which aims to port most of the usual PHP functions into equivalent JavaScript ones.

There are two ways of using this excellent codebase:

  • grab all the available PHP.JS functions and use them as you need them
  • take each function you really need and put it into your JS codebase for the project

The advantage of the second method is that you don’t have code you don’t need included all over the place, but it also means you will search each time the codebase to discover the code you need. Meanwhile, the first solution seems appropriate for the ones in a hurry, you just try to use one function like you’re accustomed in PHP and it’s there already included, you’re developing fast and safe, with just a small performance issue you can always address later.

Let’s say you’ve using the long2ip and ip2long PHP functions for storing IPs as numbers, and have a strong preference for using them for performance reasons, as all your IPs are stored as numbers in the database. What if you need similar functionality in JavaScript? Well, just take the code you need and use it! It’s that simple :-)

Leave a Reply