Sabtu, 25 Februari 2012

v8js - Integrasi PHP dan V8 Javascript Engine

v8js adalah ektensi PHP untuk melakukan embed V8 Javascript Engine kedalam PHP. Bagi yang belum tahu, V8 adalah Javasript engine Open Source besutan Google. Javascript V8 ditulis dengan bahasa pemrograman C++ dan digunakan oleh Google Chrome, browser open source dari Google. V8 Javascript diimplementasikan berdasarkan ECMAScript yang dispesifikasikan dalam ECMA-262 dan dapat berjalan diatas Windows, Mac OS X, dan Linux baik standalone atau embed dalam aplikasi C++.

Kembali lagi v8js, inti dari ekstensi adalah menjalankan Javascript dengan PHP. Berikut ini adalah contoh kode dari v8js

$v8 = new V8Js();

/* basic.js */
$JS = <<< EOT
len = print('Hello' + ' ' + 'World!' + "\\n");

try {
  var_dump($v8->executeString($JS, 'basic.js'));
} catch (V8JsException $e) {

Namun sebenarnya banyak yang mempertanyakan dalam kondisi apa ekstensi ini digunakan. Berikut ini adalah beberap komentar mengenai kode diatas:


It says I should write more of that, but I can't. This is really no test of the notes system. - Anonymous
PHP is awesome and all, but please, for the love of God, please stop trying to code JavaScript in it! All this does is encourage bad programmers to write even worse JavaScript. - robertwhurst at gmail dot com

Quality web applications are constructed with JavaScript written properly; in a .js file, If one file is to small the use a module system like RequireJS. - hello at lutoma dot org
What… the… seriously? I mean… like, this is no april fools, right?
I am now gladder than ever I stopped using PHP a long time ago - hello at lutoma dot org
While the usefulness of embedding javascript into PHP may not seem immediately obvious, a highly useful scenario presents itself to me immediately: The ability to run phpunit test on not only your PHP functions, but also the .js files used within your application!

Yes, there are JS unit tests, but the utility of having everything in one place with proper deps checking should not be ignored. -ben at chico dot com
That has to be the single worst idea I've ever seen. Please, make it stop. - evilgenius at nefariousplan dot com
this is really weird. i hope it's an april fool O.O - NetAndr
This feature is a response to node.js project. Coding javascript on the server side. Don't mistake serverside code for clientside code.- SFera
Ada pendapat? silakan tulis di komentar...

Artikel Terkait

Tidak ada komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...