×
  • Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
 

php.js

on

  • 326 views

天下一altJS武闘会で発表しました http://connpass.com/event/6402/

天下一altJS武闘会で発表しました http://connpass.com/event/6402/

Statistics

Views

Total Views
326
Views on SlideShare
326
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via SlideShare as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    php.js php.js Presentation Transcript

    • php.js うさみけんた@ぞ 2014-06-08 天下一altJS武闘会
    • お前誰よ • うさみけんた a.k.a Zonu.EXE(ぞ) • 2012年秋に自宅警備職を廃業いたしました • 仕事ではPHPとかPHPとかPHPを書いてます • 情弱いのでIDEとかよくわからなくて、
 EmacsとVimで開発してます
    •          /              /        ,イ               /       //                    |       /         ,ィ介i      |   う  ぶ  き       {. |l     ,イ  ///||     |   ち   っ え      ,-.、Vl      / | /// | |    」  に  と  ろ       lこ!l ! ト   ト.l | !i  | ヽト、<   な  ば       |  l Vヽ  トjヽ\!l   ,>‐_ニヽ     さ      |  |   \ ! く__・、jiLノ・_´フ .||   れ      | | __   ヽ} -‐   -─‐  レヘ.   ん    _r‐j   >イ fヽ  l   ノ  __    ,イ-ハ   / ′、   i   {ノ-、 ヽ  `t_/  /| /´ヽ  〈 ヽ    l   |  }   \    -' j  |   \   ヽ          /     |  ̄     L   ヽ       / -─ フ′          `ヽ─- 、    ヽ     ヽ  /`ー-、   ,. -─ '/    ー- 、     f‐--── 'ヽ {     ~    /  /, -──‐-\   /|         | ヽ         / ///        ヽ 最強言語の話をします
    • PHPとは何か
    • <?php $n = 100; for ($i = 1; $i <= $n; $i++) { if ($i % 3 === 0) { ?>Fizz<?php } if ($i % 5 === 0) { ?>Buzz<?php } elseif ($i % 3 !== 0) echo $i; ?> <?php } 人気のテンプレートエンジン
    • php.js
    • 会場に来るまで 気がつかなかったんだけど
    • _人人人人人人人_ > 二種類ある <  ̄Y^Y^Y^Y^Y^Y ̄
    • php.js implements PHP functions in JavaScript (kvz/phpjs, phpjs.org)
    • kvz/phpjs 2008年3月〜 PHPの函数を たくさん移植してる
    • date("Y-m-d H:i:s", strtotime("1 week ago”)) // => "2014-06-01 15:04:19" PHPのべんり機能がJSから!
    • % cat myphp.js require('phpjs').registerGlobals(); console.log(array_merge([1,2,3], [1,2,3])); ! % node myphp.js [ 1, 2, 3, 1, 2, 3 ] ! % php -r 'var_dump(array_merge([1,2,3], [1,2,3]));' Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 1 [4] => 2 [5] => 3) array_mergeもあるよ
    • PHP to JavaScript converter and VM written in JavaScript (niklasvh/phpjs, phpjs.hertzen.com)
    • niklasvh/phpjs 2012年1月〜 JS上にPHPのVMを構築してる
    • php.js console
    • <?php $n = 100; for ($i = 1; $i <= $n; $i++) { if ($i % 3 === 0) { ?>Fizz<?php } if ($i % 5 === 0) { ?>Buzz<?php } elseif ($i % 3 !== 0) echo $i; ?> <?php } PHPのテンプレート
    • $("n")._($$(100)); LABEL0: for( $("i")._($$(1)); ($("i"). $S_Equal($("n"))).$Bool.$; $("i").$PostInc().$ ) { ENV.$Timer(); if ( ($("i").$Mod($$(3)).$Identical($$(0))). $Bool.$) { ENV.$ob(“Fizz"); }; if ( ($("i").$Mod($$(5)).$Identical($$(0))). $Bool.$) { ENV.$ob(“Buzz"); } else if ( ($ ("i").$Mod($$(3)).$NIdentical($$(0))).$Bool.$) { ENV.echo( $("i") ); }; ENV.$ob(" n”); }; JavaScriptの式に変換
    • 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 実行出力
    • Real World php.js<!DOCTYPE html> <title>php.js</title> <script src="PHP.min.js"></script> <script src="adapters/filesystem/xhr.js"></script> <script type="application/x-httpd-php" id="init"> <?php $n = 100; for ($i = 1; $i <= $n; $i++) { if ($i % 3 === 0) { ?>Fizz<?php } if ($i % 5 === 0) { ?>Buzz<?php } elseif ($i % 3 !== 0) echo $i; ?> ! <?php } </script> <script> var init_code = document.getElementById(“init").innerHTML, path = window.location.pathname, opts = {SERVER:{SCRIPT_FILENAME: path.substring(0, path.length - 1)}};opts.filesystem = new PHP.Adapters.XHRFileSystem(); engine = new PHP( init_code.replace(/n/g,"rn"), opts), result = engine.vm.OUTPUT_BUFFER.replace(/</g,”&lt;").replace(/>/g,"&gt;").replace(/n/g,"<br />”); document.write(result); </script>
    • php.jsのどこが 最強だったか
    • TIOBE Index for May 2014
    • 私からは以上です
    •           トv'Z -‐z__ノ!_         . ,.'ニ.V _,-─ ,==、、く`       ,. /ァ'┴' ゞ !,.-`ニヽ、トl、:. ,     rュ. .:{_ '' ヾ 、_カ-‐'¨ ̄フヽ`'|:::  ,.、     、  ,ェr<`iァ'^´ 〃 lヽ   ミ ∧!::: .´       ゞ'-''ス. ゛=、、、、 " _/ノf::::  ~     r_;.   ::Y ''/_, ゝァナ=ニ、 メノ::: ` ;.        _  ::\,!ィ'TV =ー-、_メ::::  r、        ゙ ::,ィl l. レト,ミ _/L `ヽ:::  ._´        ;.   :ゞLレ':: \ `ー’,ィァト.::  ,.        ~ ,.  ,:ュ. `ヽニj/l |/::           _  .. ,、 :l !レ'::: ,. "               `’ `´   ~ ご静聴ありがたうございました
    • 発表後の追記
    • /(^o^)\