
PHP API in JavaScript. A brief overview of PHP.JS
Laziness is the engine of progress. People are constantly creating things designed to facilitate their difficult share. It was laziness that allowed the rag and mop to turn into a washing robot vacuum cleaner. Similar processes are taking place in the field of computer technology. Instead of being content with programming in machine codes, communicating with the processor through the punch card interface, people began to come up with all sorts of keyboards, mice and monitors, as well as programming languages. The latter became more and more high-level. As a result, we have what we have - a far from complete list of PL. Having enjoyed all the splendor of this variety, programmers suddenly began to realize that now they were too lazy to learn all these languages, and they began to dream of uniformity on all platforms. So JAVA was born. Those who were too lazy to teach her continued to dream and write in JavaScript. Their dreams were heard, and on the other hand node.js. So what do we do now? - PHP programmers thought, looking enviously at someone else's happiness. Rolling up their sleeves, they began to work hard, so the php.js project appeared.
Surprisingly, this noteworthy resource is mentioned on Habré only in passing. I will fill this obvious gap.
I'll start by translating the About page :
php.js is a site that provides community-created JavaScript alternatives for PHP functions.
If you want to perform high-level actions on platforms with JavaScript such as web browsers, node.js, etc., then you probably have to sit down at JS code that combines low-level language functions and build them until you get something useful like: strip_tags (), strtotime (), number_format (), wordwrap () or date ().
PHP is a language with many high-level functions, but despite the fact that they are not always implemented as uniformly as we would like (most often because they repeat the underlying functions in C), this language has a huge number of followers who are used to this syntax, so it would be reasonable to take its API as a basis, at the same time relieving itself of the need to write our own documentation, which in general, we hope, can make our life a little easier.
On the other hand, appreciating JS for its attractive features, we encourage you to explore them. Never use php.js as an excuse for not wanting to devote time to it. For the same reason, we do not port the entire PHP language or all of its control structures; we chose functions only.
It should be added that regarding porting in general as a definite call, we decided to include even such low-level PHP functions as strpos, despite the fact that JavaScript can have their close counterparts (String.indexOf). In addition to an intellectual challenge for ourselves, such porting opens up php.js, both for all kinds of mental exercises, and allows it to serve the purpose of learning JS. Thus, we see ourselves as a kind of great resource, and the developers themselves can decide when it makes sense for them to take something from here. And when not.
For collaboration we use github . Comments on the site are for comments only. Please read our guides on the Wiki .
php.js has a dual license - MIT and GPL. This means that you can use php.js according to the terms of either the MIT license or the GNU Open License Agreement (GPL) Version 2. (comparative analysis of author's licenses)
The MIT license allows you to use this library in any form suitable for you, even in commercial projects, as long as you retain the original license when distributing your product. In fact, you do not even need to disclose your modifications, although this would be highly desirable and, in addition to this, would give you confidence that your changes will not be lost after the upgrade. On the other hand, the GPL makes this library compatible with other GPL projects.
So, first of all, this project will be useful for developers who are familiar with PHP and its libraries. The vast majority of functions work in the browser, perhaps only mail and fopen for the local file on the client side will return an error (what has been done and what remains to be done is described in detail here . Volunteers ?!). But even if for some reason you are not familiar with PHP, but use JS in your projects, then this resource will certainly be useful to you, at least from an educational point of view. You should not expect miracles, at the time of this writing, the library contains only 452 functions, a very distant figure from the entire volume of PHP, but, believe me, there are plenty to choose from.
Each function on the site is provided with detailed comments and examples of use (do not forget about the PHP native documentation ). To get the source code for a particular function, click on the get on github link in the upper right corner of the code block. I advise you to immediately take all the sources to yourself, it will be more convenient. Since the library is very extensive, it makes no sense to combine all these functions into one large file, it will be unnecessarily heavy. Depending on the needs of a particular project, it is necessary to selectively create a library with the functions you need. It also makes sense to think of wrapping this API in some kind of container so as not to clog the global namespace. Well, do not forget about optimizing and compressing the code before sending it to the browser.
The summary can be made as follows - php.js is a stable and extensive JS library with good documentation, which can simplify / speed up the development of your projects. Since the taste and color, all the markers are different, then let this tool also appear in your arsenal, you look, when it comes in handy; or it’s just too lazy to cook another titanium bike and plan a mahogany crutch.
Surprisingly, this noteworthy resource is mentioned on Habré only in passing. I will fill this obvious gap.
I'll start by translating the About page :
About the site
php.js is a site that provides community-created JavaScript alternatives for PHP functions.
If you want to perform high-level actions on platforms with JavaScript such as web browsers, node.js, etc., then you probably have to sit down at JS code that combines low-level language functions and build them until you get something useful like: strip_tags (), strtotime (), number_format (), wordwrap () or date ().
PHP is a language with many high-level functions, but despite the fact that they are not always implemented as uniformly as we would like (most often because they repeat the underlying functions in C), this language has a huge number of followers who are used to this syntax, so it would be reasonable to take its API as a basis, at the same time relieving itself of the need to write our own documentation, which in general, we hope, can make our life a little easier.
On the other hand, appreciating JS for its attractive features, we encourage you to explore them. Never use php.js as an excuse for not wanting to devote time to it. For the same reason, we do not port the entire PHP language or all of its control structures; we chose functions only.
It should be added that regarding porting in general as a definite call, we decided to include even such low-level PHP functions as strpos, despite the fact that JavaScript can have their close counterparts (String.indexOf). In addition to an intellectual challenge for ourselves, such porting opens up php.js, both for all kinds of mental exercises, and allows it to serve the purpose of learning JS. Thus, we see ourselves as a kind of great resource, and the developers themselves can decide when it makes sense for them to take something from here. And when not.
Cooperation
For collaboration we use github . Comments on the site are for comments only. Please read our guides on the Wiki .
Who uses php.js
Licensing
php.js has a dual license - MIT and GPL. This means that you can use php.js according to the terms of either the MIT license or the GNU Open License Agreement (GPL) Version 2. (comparative analysis of author's licenses)
The MIT license allows you to use this library in any form suitable for you, even in commercial projects, as long as you retain the original license when distributing your product. In fact, you do not even need to disclose your modifications, although this would be highly desirable and, in addition to this, would give you confidence that your changes will not be lost after the upgrade. On the other hand, the GPL makes this library compatible with other GPL projects.
So, first of all, this project will be useful for developers who are familiar with PHP and its libraries. The vast majority of functions work in the browser, perhaps only mail and fopen for the local file on the client side will return an error (what has been done and what remains to be done is described in detail here . Volunteers ?!). But even if for some reason you are not familiar with PHP, but use JS in your projects, then this resource will certainly be useful to you, at least from an educational point of view. You should not expect miracles, at the time of this writing, the library contains only 452 functions, a very distant figure from the entire volume of PHP, but, believe me, there are plenty to choose from.
Each function on the site is provided with detailed comments and examples of use (do not forget about the PHP native documentation ). To get the source code for a particular function, click on the get on github link in the upper right corner of the code block. I advise you to immediately take all the sources to yourself, it will be more convenient. Since the library is very extensive, it makes no sense to combine all these functions into one large file, it will be unnecessarily heavy. Depending on the needs of a particular project, it is necessary to selectively create a library with the functions you need. It also makes sense to think of wrapping this API in some kind of container so as not to clog the global namespace. Well, do not forget about optimizing and compressing the code before sending it to the browser.
The summary can be made as follows - php.js is a stable and extensive JS library with good documentation, which can simplify / speed up the development of your projects. Since the taste and color, all the markers are different, then let this tool also appear in your arsenal, you look, when it comes in handy; or it’s just too lazy to cook another titanium bike and plan a mahogany crutch.