Hacker News new | past | comments | ask | show | jobs | submit login
PHP.JS: use your favorite PHP functions client-side (phpjs.org)
43 points by ajbatac on May 28, 2009 | hide | past | favorite | 22 comments



At one level, this horrifies me.

At another level, I'm always impressed by how PHPers just do it. Whatever it is, you always just seem to get from A to B and have something up and running. You guys are like the weaver ants of the programming world.


I guess PHP programmers should never expect anything more than a backhanded compliment. I just love how any topic that just contains the word PHP immediately gets a comment on how awful it is - even if PHP isn't really involved in it.


How is PHP not really involved? It's all the built-in PHP functions! Do you just mean it's not a PHP Group project?


PHP isn't really involved because this is only "like" PHP. It has no PHP in it. As far as I know from a quick skim.


It doesn't run in PHP, but it borrows function signatures from PHP's core library. One of the most common complaints about PHP is that the core library is messy and inconsistent.

edit: I didn't mean to sound so negative. I think this is pretty cool if taken for what it is. Despite the messiness of PHP's libraries, they are well documented and cover a lot. The string, date, and array libraries in particular are quite useful.


Dude, the echo function contains an XML parser. That is truly something only a PHPer would do. It's art, man!


What specifically horrifies you about it? There are a lot of utility functions in PHP that aren't built-in to Javascript. I've used it a little by looking at the source for the code and tweaking things here and there.

This isn't really a way to turn Javascript into PHP. PHP simply has a lot of functions that are handy. Some problems that I can think of are that it brings in PHP's namespacing and lack of naming conventions, but these can be fixed if a developer only incorporates one function at a time when he or she needs it.


Some problems that I can think of are that it brings in PHP's namespacing and lack of naming conventions.

That's a part of it, along with some of the kind of weird function semantics, along with just the general idea of "Hey, we should port all the built-in PHP functions to Javascript!" followed by it actually getting done.

If the idea was simply "let's port the useful functions in PHP that makes sense for javascript", that would be one thing. As that idea is actually a subset of this project, no harm done, I guess. Thank goodness we finally have "die" for javascript, right?


I love the print_r function I found this because I was searching specifically for that.

On the other hand, I do not need the curmudgeonly array functions. Why anyone would want to recreate the frustrating hell of having to know which array functions are (needle, stack) and which are (stack, needle) is beyond me.


I have been using this reliably for over a year now. They have the bulk of the functions already done that you'd want: http://phpjs.org/statistics/index . Extra nice: you can download the js one function at a time, if you so choose. Similar alternative for date(): http://www.svendtofte.com/javascript/javascript-date-string-...


Thanks. It is always good the read comments from someone who actually used it for over a year. This reinforces me to use this on my next project.


Thanks for posting this. Regardless of the attitude towards PHP on HN, this looks a very solid library, making my life easier. I hate having to create my own JS functions for search, replace, trim etc., let alone easy to use date functions.


I feel the same. I am very familiar with the PHP functions -- php.net is the greatest -- but for JS, I'm a little weak. This will definitely make my life easier on the client side (+jQuery).


I've been using this for a while - I'm a bit of a n00b when it comes to Javascript but have been using PHP since 2000 - it makes my life loads easier!


I don't know if I understand this. The Library is HUGE(Yes, I know you can compile your own package), the minified version is over 100KB. Thats 100KB to have JavaScript functions using PHP syntax, many of which duplicate functions that already exist as part of JavaScript.

I'm not down on PHP or anything, but much of this seems redundant and a waste of time.


Can anyone with real experience using PHP.js tell us what size file is generated when you COMPILE your own package?

I am wondering how far the code dependencies spread out when you use, say a dozen of your favourite PHP functions, ... Does that force the inclusion of dozens more sub-functions within PHP? Does your compiled file climb towards the all-inclusive 100 KB?


I'm sure gzipping will help the download size.


This is an excellent tool to get things up and running on the client side for the large number of people who are fluent and proficient in PHP.

Even if you are concerned about efficiency, it is still excellent as a fast prototyping method, where you get something up and running so you can interact with it, test new ideas, and so on.


Reading the implementation of these functions is truly enjoyable. "echo" implements its own XML parser! (I wish I was making that up.)

The writing style the docs use is also nice. The developers are always referred to as "rock stars", and the examples are always in the form "If you write ..., it could return ...". could return? Nice.


Not to be the hater in this thread, but I bet this was made by a bitter JS developer who saw how jQuery undid most the evils of Javascript and felt that the "damage" had to be rectified.

To add something constructive to the debate, I'll just toss in that this goes right in the face of good API design, not as a cheap pun because it's PHP, but because it's a PHP API transliterated into a language not PHP.


Say what you will about the big ball of mud that is the PHP function library, it is still useful. Sometimes just being able to call a simple function is refreshingly straight forward. "Good" API design these days seems to mean including the entire alphabet of OO design patterns.

I'm particularly interested in the PHP date() function myself, since the date handling in Javascript is seriously insufficient.


And now that php is going to have cleaner anonymous functions we'll end up with some sort of pquery. but with more -> and Array( all over the place.

P("db_table.name")->filter(function($x, $y){return $x > $y;});




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: