Live data from Hacker News

PHP: v8.js

php.net

21–30 of 43 posts

Re: PHP: v8.js

#21
post #11

Earlier quoted context omitted.

"or running the same form validation code on both the client- and the server side." That sounds great until you realize that you usually do a lot more validation on the server than on the client (is the username taken, is password correct, etc etc). So you would still have to use PHP for validation (in most cases).

Sure, but only for the cases not covered by the JS.

I was trying to say that you don't really gain anything in this case. You would load some JS file (which would probably have to be written in a way that it could be used this way) just do do some simple validation (if (someField!='') for instance). Doesn't seem like worth the bother to me.

Re: PHP: v8.js

#22

I have been doing a lot of work with PHP recently, and reading through their library docs, it seems to me like they will put anything in a core extension, regardless of whether it's something that really belongs there.

> I have been doing a lot of work with PHP recently

If you've been doing a lot of work in PHP recently, then you should be compiling your own PHP. Which gives you the option of disabling every extension. The PHP core is actually very lean. Virtually everything is an extension. They even have a nifty flag to disable everything.

I like having the option of compiling a bazillion extensions in the binary if I want to. Even though I never enable anything beyond the basic stuff I need.

Re: PHP: v8.js

#23

do. not. want. If you think this is anything but the worst idea ever - trust me; you're doing it wrong.

Can you elaborate?

Let's see. Practically - a web templating language with weakly-typed bolt-on OO 'featurettes' now has an embeddable, weakly-typed, object-oriented scripting language. Hello run-time heisenbugs that can NEVER be unit tested nor debugged.

Anecdotally - let's face it; there is no shortage of crappy php and javascript out there. This is an open invitation to merge the two into one extraordinary megaclusterfark.

Re: PHP: v8.js

#24

one possible use can be executing some JS code even if JS is disabled in browser

yes but that would require server to know that which again requires some sort of ajax which cannot happen because js is disabled!

Re: PHP: v8.js

#25

It looks like a PHP extension to embed JavaScript using the V8 engine. The docs are pretty limited. The return value of executing a blob of JS is described thusly: "Returns the last variable instantiated in the Javascript code converted to matching PHP variable type." I supposed the mapping is obvious, to someone :). I'd personally want to know if JS objects come back as stdClass objects or assoc arrays. It could def…

I imagine the objects would come back as stdClass as this is the behaviour when decoding JSON objects with json_decode(). I assume other type-mappings will match the behaviour of json_decode() too.

I can't think what the result would be if the last variable instantiated in the JavaScript code was a function though; perhaps null, or an exception would be thrown.

Re: PHP: v8.js

#26
Pretty mingtastic API for a first attempt, it's not safe, and is sure to suck performance wise, since all interaction must involve parsing an expression, and coercing any return value back to a PHP type, and with no way to maintain references to native JS objects.

I wouldn't object so much if only the PHP community weren't already known for their tendency to take a bad situation and make it worse: can't we learn from the history of mysql_query() and friends? Decades of SQL injections! There's no reason they couldn't provide a nice "JsObject" type supporting __call() and __get() to allow integration without resorting to interpolating bits of JavaScript code with (probably originating from a user) data, this way at least web developers would be safer from themselves.

Re: PHP: v8.js

#28
Unfortunately, there are some bugs with the variable passing. You should be able to pass an array of variables to the V8js object and have access to them under PHP js object. However, the values are currently set to null.

In my experimentation I wanted to see [in php after js execution] all the variables created in the global scope. There are two ways to do it, pass the flag to the V8js constructor to make executeString return associative arrays and add "this;" to the tail of the scripts you execute. Or, append "JSON.stringify(this);" to the tail of the scripts.

The first method will return everything including references to print, var_dump, sleep and exit methods that are bridged from PHP.

The stringify method will give you just the variables without the method references but tends to leave you with empty arrays if all your array indices point to null values. Which is misleading if the result is "someVal: {}", verses "someVal: {'foo': null, 'bar': null}".

What it misses most, is the ability to bridge your own method calls. Would be nice to be able to register a method call in JS that executes a user defined PHP function.

Re: PHP: v8.js

#29
This is interesting, and I saw the one Example (Hello World) they have on the site.

So I guess my question is, why? What's a real use case example of why'd I want this? PHP isn't syntactically more tragic than JS. JS doesn't have so many more libraries than PHP already has? I can't see why someone would use this? Maybe to hook into GWT librarieS?

Re: PHP: v8.js

#30
That is a great idea, a scripting language riddled with design flaws integrated into a scripting language riddled with major design flaws, gaping security holes, a over-zealous and wrong tokenizer, extra transparent features that will fuck you over where they can, an incompetent maintainer, a terrible API..
Post reply on HN