Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHP帝国の逆襲!(を願うPHPerが話す最近のPHPについてのクイックツアー PHP7対応版)
Search
uzulla
August 20, 2015
0
440
PHP帝国の逆襲!(を願うPHPerが話す最近のPHPについてのクイックツアー PHP7対応版)
YAPC::Asia tokyo 2015
uzulla
uzulla
August 20, 2015
Tweet
Share
More Decks by uzulla
See All by uzulla
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
99
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
170
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
110
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
1.9k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
890
PHPerが ISUCONでやるべき事
uzulla
1
830
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
220
test is not a job
uzulla
1
480
あなたのPHPアプリ、ログはでてますか?あるいはログをだしてますか? / Are you writing a log? Or just out a log?
uzulla
17
7.4k
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.3k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Transcript
̥̝̥ఇࠃͷٯऻʂ • ͜ͷτʔΫϠδOKͰ͢ • ͜ͷτʔΫস͍ͬͯͩ͘͞ • υϯυϯֻ͔͖ͬͯͯཉ͍͠
who am i ? UZULLA PHPer Hachioji.pm ʮϝʔϧϑΥʔϜΛॻ͍ͯੜ׆ʯ
Σϒք۾Ͱ ༗໊ͳʮPHPʯ ͕ɺͲΜͳͷ͔ օ͞Μͬͯ·͢ ͔ʁ
͕࣌ؒͳ͍ͷͰ! • ڈͨ͠ʮͳPHPDisʯͰάάͬͯͩ͘ ͍͞ • ࡢYAPC::AsiaͰҰ൪έͨ(?)τʔΫͰ͢ • ࠷ۙͷPHPͷۃॳาతͳ͜ͱղΔͣʢʁʣ • https://www.youtube.com/watch?
v=2tZxNtn0kDc • http://www.slideshare.net/junichiishida/ yapc-2014-phpuzullatalk
ࡾߦͰ • PHPJavaͱPerlͱHTML/JSΛ·ͥͨΑ͏ͳ • ςϯϓϨʔτΤϯδϯͰ͢ • ʮΏΔ;Θ͆͆͆͆͆ʯ
ʮΏΔ;Θݴޠ͆͆͆ʯ • ࠷ۙͷPHPਅ໘ʹ͔ͭ͏ͱΏΔ;ΘͰͳ ͍ • ·͋ͰΏΔ;Θʹॻ͚Δ • ੍ࣗ৺ΛͬͯऔΓΉͷ͕ਖ਼͍͠PHPerͷ SUTAIRU
PHPఇࠃͷٯऻ • ʮٯऻͷͨΊʹணʑͱྗΛ͔ͨΊͭͭ͋Δ͕ɺ ຊฤʹೖΕͳ͔ͬͨΑ…ʯ • ʮͬͱ͕ΜΖ…ʯ
ʮPHPఇࠃਓࡐΛืूதͰ ͢ʯ • Έͳ͞ΜʹPHPΛॻ͍ͯΒ͍͍ͨ • ͦΕ͕ࢲͷΈͰ͢
͓ॻ͖ • དྷͨΔ͖PHP7ʹ͍ͭͯ • PHPͷΤϥʔʹ͍ͭͯ • ࠷ۙͷhttpdʹ͍ͭͯ • PSR-7ʹ͍ͭͯ •
ʮ͋ͷਓࠓʯ
ʮۙະདྷPHPηϒϯʂʯ • ʮVarsion 7.0.0ʯ • ݱࡏbeta3ɺࠓͷౙstable༧ఆ • PHP6ແ͔ͬͨࣄʹʢ৭ʑ͋ͬͨʣ • ळʹ5.4EOL!ɺ5.5طʹSecurity
fixes only http://php.net/supported-versions.php
·ͣ
!!!!!! RC1 Release YEAH!!!! !!!!!!
ࡾߦͰղΔPHP7 • ഒ͘Β͍͘ͳͬͨ! • ͍ํߏஙํ๏มΘ͍ͬͯͳ͍" • จ๏͕ਐԽɺPHPίʔυޓੑଟগյΕͨ# • ͞ͱҾ͖ସ͑ʹC֦ு܈͕க໋ইΛෛͬͨ$
͘ͳͬͨ݅ • ഒ͘Β͍͘ͳͬͨ • PHP7 >>>> PHP5.6 > PHP5.5,5.4 >>
PHP5.3 • (HHVM)
None
None
None
None
None
None
ग़య https://kinsta.com/blog/hhvm-vs-php-7/ http://blog.litespeedtech.com/2015/07/24/ php-7-vs-hhvm-benchmark-series-2-wordpress/ http://blog.litespeedtech.com/2015/07/16/ php7-vs-hhvm-benchmark-series-1-hello-world/ https://www.zend.com/en/resources/ php7_infographic http://hhvm.com/blog/9293/lockdown-results- and-hhvm-performance
https://ckon.wordpress.com/2015/08/09/
Կނ͘ͳ͔ͬͨʁ • ʮ͔ͤͬͭΕͨPHPਞӦ͕ຊؾͩͨ͠ʯ • ओʹมͷϝϞϦ্ͷߏ͕มߋ • ʮ΄Μͷͷ͍Εͭʂʯ • zvalͰάά͍ͬͯͩ͘͞ •
(ͦͦԶ͕ͦΜͳʹৄ͘͠ͳ͍) • ঈͱͯ͠ɺC֦ு͕Ұશ໓ͨ͠ʢޙड़ʣ
ࠓޙ͘ͳΓͦ͏ • HHVMͷ༷ͳJITԽΛݟਾ͍͑ͯΔΒ͍͠ • ASTΛ࡞ΔΑ͏ʹͳͬͨ • ͞Βʹ͕৳ͼΔՄೳੑ
͍ • ͘ͳͬͨҎ্Ͱ͢
PHP7Ͱ͍ํมΘ͔ͬͨʁ • php-fpmΈ͍ͨͳͷ͕૿͑ͨͱ͔ͦ͏͍͏ͷ ແ͍ɻ • ࠓ·Ͱ௨Γͷmod_php,php-fpm,php(-cgi) • Ϗϧυํ๏΄΅ಉ͡ • Stable͕ͰΕɺී௨ʹaptʹΔͰ͠ΐ͏
• yumԿޙͩʁ(Ϩουϋοౘஊ
҆ఆ͍ͯ͠Δ • ͍··Ͱ௨ΓɺԿߟ͑ͳͯ͘མͪͮΒ͍ɻ ҆ఆ͍ͯ͠Δɻ • ʮPHP͕҆ఆʂʁʂʁʂʁʯ • ʮಔᮐύʔιϯʯͱ͍͏ࣾձ࣮ݧ • ·͋ɺॏ͘ͳΔ͚Ͳͳ͆
httpdपΓͰ… • ࠷ۙH2Oͱ͍͏httpd͕͋ΒΘΕ·ͨ͠Ͷʂ • ผʹPHPͱ͍͕ؔ͋͢͝ΔΘ͚Ͱͳ͍͚Ͳ • ͕࣌ؒ༨Ε͠·͢ɻ
PHP+httpdʹ͍ͭͯ • Apache+mod_php , (Apache+fastCGI) • nginx+fastCGI • H2O+fastCGI ,
H2O+CGIϚωʔδϟ • nginx+Apache+mod_php
Apache+mod_php • mod_phpͱ͍͏మ൘ • yumaptͰೖΔ • ΄΅ઃఆϨε͔ɺ.htaccessͰࡁΉ • ʢσϑΥϧτͰʣଟίωΫγϣϯʹऑ͍ •
͞ΕͲమ൘
Apacheͷઃఆ # httpd.conf LoadModule php5_module modules/libphp5.so <FilesMatch ".+\.php$"> SetHandler application/x-httpd-php
</FilesMatch> # .htaccess RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]
༨ஊɺҰߦAddHandlerηΩϡϦςΟతʹϠό ͍ # httpd.conf AddHandler php5-script .php • Α͘ݟ͔͚Δهड़͕ͩ… •
http://d.hatena.ne.jp/tmatsuu/ 20150221/1424531513 • AddHandlerผʹʮ֦ுࢠʯͰͳ͍ͷ Ͱɺ.php͕ϑΝΠϧ໊Ͳ͜ʹ͍ͬͯͯPHP ͱͯ͠ղऍ͞ΕΔ᠘
nginx+php-fpm • ࠷ۙͷఆ൪͔ʁ • ࣮ࡍ͍ • nginxͳΜͰͰ͖ΔɺຊʹԿͰɻ • ݁ՌɺઃఆෳࡶʹͳΓ͕ͪ
nginxͷίϯϑΟάྫ index index.php try_files $uri $uri/ $uri/index.php /index.php; location ~
\.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # !ͷઃఆϑΝΠϧͷதʹେྔͷઃఆ͕Ӆ͞Ε͍ͯΔ…ʂ include fastcgi_params; } • ղΓͮΒ͍ʂʂʂʂʂ • ͜Ε͚ͩͰμϝͳࣄ͋Δ
nginx㙽ʹ֯͘͜͠ͳΓ͕ͪ • FastCgiͷ߹Ͱ͋Δͷ͚ͩΕͲ… • /formͳͲɺPHPϑΝΠϧ໊͕ͳ͍URLΛ͏ ߹… • try_filesΛͪΌΜͱཧղ͠ͳ͍ͱμϝ • locationΛͪΌΜͱཧղ͠ͳ͍ͱμϝ
• fastcgiͷύϥϝλΛͪͪ͘͘Ճͨ͠Γ • PATH_INFOΛͲ͏ੜ͢Δ͔ͰΉ
H2O+fastCGI , H2O+fcgi.spawn • ظͷ৽ਓ • http/2 • ઃఆϑΝΠϧ͕γϯϓϧʂ •
ͦͷ··ͰߴʢΒ͍͠ʣ • ·ͩݟগͳ͍
h2o+php-fpm file.custom-handler: extension: .php fastcgi.connect: host: 127.0.0.1 port: 9000 type:
tcp hosts: "doraperson2015.yapcasia.org:443": paths: /: file.dir: /var/www/dora-person-election/app/htdocs redirect: url: /index.php/ internal: YES status: 307
h2o+php- cgi(fastcgi.spawn) file.custom-handler: extension: .php fastcgi.spawn: "PHP_FCGI_CHILDREN=10 exec /path/to/php-cgi" •
phpϓϩηεͷੈΛh2oʹ·͔ͤΒΕΔʂ • php-fpmෆཁɺࢹ͕ݮΔ! • ɺͺͬͱݟphp-fpmͱḮ৭ͳͦ͞͏ • php-fpm.confͳͲΛॻ͔ͳͯ͘ྑ͍"
h2oॴݟ ྑ͍ • ຊਓͷkazuho͞Μ͕ͭͬͯ͘Δʂʂ • ࣭͢Δͱɺ͓͑ͯ͘͠Εͯ͞͠ ͍ʂʂʂʂ • ଞʹ͘Βɺ࠷ݶͷઃఆϑΝΠϧγϯϓϧ Ͱ͋Δ
• ϑΝΠϧ֦ுࢠʹͻ͍ͮͯΔͷͰɺ҆શ • fastcgi.spawnศརʂʂʂ
h2oॴݟ ଟ͜Ε͔Βͷ • .htaccessແ͍ͷͰɺڽͬͨઃఆͩͱͬͺ Γ͍ • try_filesతͳ֓೦Θ͔Βͳ͍ͱ… • ͽͪͺʔʹϏϧυ͕໘ •
yumͱ͔aptͱ͔΄͍͠ΑͶ͆ • ઃఆͷൿͷͨΕ·ͩগͳΊɺಛʹӡ༻ • ߏ͕গʑಠಛɺinit.dͳͲͲ͏͢Δʁ
ͲΕ͕ྑ͍͔ • ʮଟগͯ͘άάΕղܾ͢ΔApacheʯ • ʮnginxͷίϯϑΟάɺෳࡶ͗͢ͳ͍ʁʯ • ʮH2Oʢ·ͩʣάάͬͯղܾ͠ͳ͘ͳ͍ʁʯ • దࡐదॴ
༨ஊɺPHPΰϛΛ٧ΊࠐΉจԽʁ͕͋Δ • ઃఆ͢ΔػೳຖͰͳ͘ɺΞϓϦຖͰԡ͠ࠐΊΔ ͱPHPͬΆ͍ • .htaccesshttpdͷઃఆ͔ΒURLϚοϓΛͻ͖ ͕ͯͯ͠ɺָ • PHPͷαΠτࠞࡌʹͳΓ͕ͪɺΠέͯΔํ๏ ͕ͳ͍ͷ͔ͱͳ·͍͠ɻ
• ࠶ىಈ͕ඞཁͰ͍͍͔Βɺ.htaccessΈͨ ͍ͳͷ͕΄͍͠…
bench • έʔεόΠέʔε͗͢Δ… • Apacheͷνϡʔϯ໘ • nginxയવͱ͘ͳΔ͕ɺྑ͍ઃఆͰΉ • ʮH2Oύϥϝλ͕σϑΥϧτͰΠέͯΔʂʯ ͱ࡞ऀ͕ओுͯͯ͠ΛసՇͰ͖Δ(?)
͞Βʹ༨ஊ • PHPPaaS;͖͑ͯͯ·͢ • Heroku • Azure app service •
Google App Engine • ͍ͣΕਖ਼ࣜʹʢͱ͍͑ɺ·ͩPHP5.5ɺ. 6͘Β͍ʣ
͍
PHP7ͷඇޓੑͷ • ʮϚΠφʔͰޓੑ͕յΕΔࣄʹʢҰ෦Ͱʣ ఆධͷ͋ΔPHPʯ • ϝδϟʔόʔδϣϯΞοϓͳͷͰյΕͨ!
લ͖ͳํͷඇޓੑʢޙड़͠·͢ʣ • େඇਪ͕࣮ؔࡍʹআ • ϚχΞοΫͳՕॴͷڍಈͷมԽ • ࡉ͔͍จ๏ͷඇޓੑ • ༧ޠ
݁ߏ೦ͳํͷඇޓੑ • C֦ு(ॴҦpeclͱ͔)ͷඇޓੑ • gdͱ͔͋Δ • memcacheʮdʯ͋Δ͚Ͳɺmemcache ͳ͍ • redisͱ͔ɺQueueܥͱ͔͕ʢ·ͩʣͳ͍
• PPͷͷ(େମ)ಈ͘ • Release·Ͱʹͬͱ૿͑Δͣ
ʮ͜ͷઌੜ͖Δʹʯ • ʮC͕Θ͔Βͳ͍PHPer͔ͭ͠ͳ͍Α Ͷ…ʯ ʮ͑ͬPHPerͬͯCΘ͔Βͳ͍ͷʁʯ • ϝδϟʔॴϘνϘνରԠ͞Ε͍ͯΔ • C֦ுΨϦΨϦॻ͍͖ͯͨํʑɺ͔ͯ͠͠ ݟΓͷλΠϛϯά͔͠Εͳ͍͆
ʢҰ෦ͷXSΛॻ͘CPANԦαʔͷօ͞Μʣ • ʮͲ͔ͬͰฉ͍ͨ͜ͱ͋Δͩͳʯ • ʮ෦APIมΘΔͷɺ͔ͨ͠ͳ͍͚Ͳ͎ŵŧƄແ ཧ…ʯ
͍
ݴޠͱͯ͠ͷվળ • ඇਪͷΓࣺͯ • Type HintingվΊ Type declarationsʢܕએݴʣͷڧԽ • ΤϥʔͷऔΓѻ͍ͷڧԽ
• จ๏ͷՃ
ඇਪͷΓࣺͯ • ‼mysqleregͷϏοάωʔϜ͕͍ͭʹഇࢭ • ❗ศར(ҋ)ػೳɺpreg_replaceͷ e(eval)ഇࢭ • ❔ݹͷ=&ɺ<%ʙ%>ɺ<script language=php>ʙ</script>ͷഇࢭ •
͍ͣΕ͍͜ͱܯࠂࡁΈ • 105.3Λ͍ͬͯͯʮϏοάΣʔϒʹΖ ͏ͥʂʯͱ͍͏ॴ͕ࢮ͵
Type declarations(ܕએݴ) • ݩType Hinting • ҾฦͷʮܕʯΛࢦఆ • ʢPHPͷʮܕʯͰ͢ʣ •
ʮJava͍ʯ • ҧͰྫ֎ʢPHP<7Τϥʔʣ • 7͔ΒεΧϥΛࢦఆՄೳʹ㊗ • 7͔ΒฦࢦఆՄೳʹ"
ͷεΧϥ͕ࢦఆՄೳʹʂ <?php function func(int $num){ } func('a'); // => TypeError
Exception !" func('1'); // => OK #$ • ʮ͔͠͠'1'௨Δʯ • ʢօ͞ΜʣʮOK͡ΌͶ͑Α͆͜Ε͔ͩΒ PHPer͆͆͆ʯ
…ͱ͓͔ͬͨʁ
strict_types <?php // PHP7.0.0beta2ʹͯ֬ೝ declare(strict_types=1); // ! function func(int $num){
/* ʙ */} func('1'); // => TypeError " func(1.0); // => TypeError "" func(true); // => TypeError """ • ઌ಄ͷdeclare(strict_types=1);Ͱݫ֨ʹ • float=>int❌ͳͷɺڻ͖ͷϚοτͳڍಈ͆
ͨͩ͠ • int->floatΩϟετʮOKʯ • ʢ͕ܽམ͠ͳ͍͔ΒͩΖ͏ʣ • Type declarationsʹΑͬͯɺ༧ظͤ͵ܕΩϟε τ͕ൃੜ͢Δ͜ͱ͕…
ࣗಈΩϟετͰ͜Ε͕ΤϥʔʹͳΔ <?php declare(strict_types=1); func(1); // !ͱͱͷintͳҾ͕ function func(float $num){ //
"͜͜ͰfloatʹͳΓ func2($num); // #TypeErrorʹͳΔ } function func2(int $num){ // $func2ͷҾintࢦఆͳͷͰ } • int->floatΩϟετ͞ΕΔ! • ·͋ɺPHPΒ͍͠Ͱ͢Ͷ"
͜Εخ͍͠ɺฦࢦఆՄೳ <?php function func() : int { // ! return
1; } • Θͳ͍ਓলུ͢ΕOK
೦ʁҙʁϙΠϯτ <?php function func(){ $a = 1; return function ()
use ( int $a ) { // Error return $a*2; } } • use۟ʹʢRC1ͷݱ࣌ͰʣܕએݴͰ͖ͳ͍
ʮͱ͜ΖͰɺTypeʹԿ͕ࢦఆͰ͖Δͷʁʯ • array • callable,Closure(ແ໊ؔ) • Ϋϥε/ΠϯλʔϑΣΠε • int,float,string,bool ㊗Ճ
͜͏͍͏ͷࢦఆͰ͖ͳ͍ • ❌ : (function(int): int) • (HackͳΒͰ͖Δ) • ❌
: \DateTime[] • PHPDocͰ͓ͳ͡Έɺཉ͍͠… • ❌ : mixed • ·͊ɺॻ͔ͳ͚ΕՁ
ͬͨ࣌ɺͲ͏ͳͷʁ • ༗Γ 0.4381 sec • ແ͠ 0.3516 sec •
ࠩ 0.0865 sec(86.5ms) / Ұઍສճ • MBP i7+PHP7β2Ͱɺ10,000,000(Ұઍສ)ճ͠ ͯ͜ͷఔ • (PHPͷ༻్Ͱ)࣮༻্ޡࠩͳͷͰؾܰʹ͍ ͍ͨɻ
ࢼͨ͠ίʔυ <?php declare(strict_types=1); function func (int $num): int{ return $num;
} // ༗Γ function func2 ($num) { return $num; } // ແ͠ $start = microtime(true); for($i=0;$i<10000000;$i++){ func($i); // OR func2($i); } echo microtime(true) - $start; • ͪͳΈʹɺis_intͰࣅͨΑ͏ͳίʔυॻ͍ͨΒ ͕΄΅ಉͩͬͨ͡
͍
க໋తΤϥʔͷϋϯυϦϯά͕Մೳʹ ͳͬͨ • PHPʹྫ֎ͱΤϥʔɺೋ͕ͭଘࡏ • Τϥʔʹக໋త(Fatal)ͱඇக໋త͕͋Δ • க໋తΤϥʔ؆୯ʹϋϯυϧͰ͖ͳ͔ͬͨ • PHP7͔Β(Ұ෦Λআ͖)Fatal
ErrorΛྫ֎Ͱϋ ϯυϧՄೳ! • https://wiki.php.net/rfc/ engine_exceptions_for_php7
PHPͷʮExceptionʯ • ΈΜͳ͕ͬͯΔྫ֎ͦͷͷ • catchͯ͠ճ෮Ͱ͖Δ • Θ͔Γ͍͢ʂʂ
PHPͷʮΤϥʔʯ • ਅ໘ʹ͢ͱ30Ҏ্͠ΌΕΔͷͰ3ߦͰ • શମͰҰݸ͔͠ϋϯυϥΛొͰ͖ͳ͍ྫ֎Έ ͍ͨͳͷ • க໋తͳΤϥʔɺεΫϦϓτΛͦ͜Ͱऴྃ͞ ͤΔ(ճ෮ෆՄೳ) •
ྫɿύʔεΤϥʔɺॏෳએݴΤϥʔɺඇଘࡏؔ ίʔϧΤϥʔ • ʢৄ͖͖͍ͨ͘͠Ͱ͔͢ʁʣ
PHPͷҋਂ͖Errorʹ͍ͭͯ 1 • ΤϥʔΤϥʔϋϯυϥʹɺίʔϧόοΫؔ Λొ͢Δ(set_error_handler())͜ͱͰΩϟ ονͰ͖Δ • ϦΫΤετͰɺάϩʔόϧͳઃఆͰ͋Δ • ྫ֎ͷΑ͏ʹɺ֊ԽͰ͖ͳ͍
• ͭ·Γہॴతͳࠩ͠ସ͑Մೳ͕ͩɺඇৗ ʹෆศ
PHPͷҋਂ͖Errorʹ͍ͭͯ 2 • ϋϯυϥΛͰΤϥʔΛΩϟον͢Δͱ… • WarningsNoticeग़ྗ͞Εͳ͍ • ѲΓͭͿͤΔ • E_RECOVERABLE_ERRORεΫϦϓτΛऴྃ
͠ͳ͍ʢҙ͕ඞཁʣ
PHPͷҋਂ͖Errorʹ͍ͭͯ 3 • set_error_handler()Ͱྫ֎ʹม͢Δࣄ͕ Ͱ͖Δ set_error_handler(function($errno, $errstr, $errfile, $errline){ throw
new ErrorException($errstr, $errno, 0, $errfile, $errline); });
PHPͷҋਂ͖Errorʹ͍ͭͯ 4 • ͨͩ͠ɺக໋తͳΤϥʔଈࢮͰϋϯυϧͰ͖ ͳ͍(PHP<7) • register_shutdown_functionΛ͔ͭͬͨ τϦοΫ͕ඞཁʢ෮ؼͰ͖ͳ͍ʣ register_shutdown_function( function(){
$e = error_get_last(); if( $e['type'] == E_ERROR || $e['type'] == E_PARSE || $e['type'] == E_CORE_ERROR || $e['type'] == E_COMPILE_ERROR || $e['type'] == E_USER_ERROR ){ // ͓͖ͳॲཧΛॻ͘ echo "க໋తͳΤϥʔ͕ൃੜ͠·ͨ͠ɻ\n"; echo "Error type:\t {$e['type']}\n"; echo "Error message:\t {$e['message']}\n"; echo "Error file:\t {$e['file']}\n"; echo "Error line:\t {$e['line']}\n"; } } );
PHPͷҋਂ͖Errorʹ͍ͭͯ 5 • ൃੜͨ͠Τϥʔࣗମͷग़ྗઌมߋՄೳ • ϒϥβʔ(display_errorsͰOn/Off) • ϩάग़ྗ(stderr,syslog,ϑΝΠϧ) • ͜ͷೋͭฒྻతͳ
PHPͷҋਂ͖Errorʹ͍ͭͯ 6 • Τϥʔʹࢁछྨ͕͋Δ • ඇக໋తͳͷ • E_NOTICEɺE_WARNINGɺ E_DEPRECATEDɺ… •
க໋తͳͷ • E_PARSEɺE_ERRORɺ… • Ͳͬͪͱ͍͑ͳ͍ͷ
PHPͷҋਂ͖Errorʹ͍ͭͯ 7 • E_RECOVERABLE_ERROR(ޙड़)ʮΩϟον͢ Εʯͦͷޙ࣮ߦͰ͖Δ • ྫ͑ɺType declarationsͷҧͰग़Δ • ͜ΕΛΩϟονͯ͠Ͳ͏ʹ͔ͯ͠Δίʔυ
ݟͨࣄແ͍…
PHPͷҋਂ͖Errorʹ͍ͭͯ 8 • ΤϥʔઃఆʢϏοτϚεΫʣͰൃੜछྨΛࢦ ఆՄೳ • error_reporting(0)࠷ڧɺԿग़ͳ͍ • ʮக໋తΤϥʔͰ͢Βʂʯ •
ʮࣗʯͷύʔεΤϥʔʢE_PARSEʣ ϜϦ • includeͷύʔεΤϥʔ௨աͰ͖Δ ʢʂʣ
PHPͷҋਂ͖Errorʹ͍ͭͯ 9 • ѱ໊ߴ͍@ɺ؆୯ʹΤϥʔΛ੍Ͱ͖Δɺͦ ͏ɺFatalͰͶʂ • ͍Ͱ͢ɻ • includeͨ͠ϑΝΠϧͷύʔεΤϥʔ ʢE_PARSEʣϜϦ
• error_reporting(0)ͷํ͕ͭΑ͍
PHPͷҋਂ͖Errorʹ͍ͭͯ 10 • ༨ஊɿPHPʹʢࠓݱࡏʣίϯύΠϧϑΣʔζ ͳ͍
PHPͷҋਂ͖Errorʹ͍ͭͯ 11 • ඇக໋ͷNotice,Warningऴྃ͠ͳ͍ • Τϥʔ͕ग़ྗ͞ΕΔ͚ͩ • ѱ໊ߴ͍ʮը໘ʹग़ΔΤϥʔʯ • ʢॳ৺ऀʣʮઃఆΛίϐϖͨ͠ΒΤϥʔ͕
͚ͤ·͢ʂʯˠ(ݟ͑ͳ͘ͳ͚ͬͨͩ)
PHPͷҋਂ͖Errorʹ͍ͭͯ 12 • use strict;͕ཉ͍͠… • ͨͩɺʹͨΑ͏ͳ࡞ΕΔ • http://uzulla.hateblo.jp/entry/ 2013/12/20/041619
PHPͷҋਂ͖Errorʹ͍ͭͯ 13 • 㙽ʹ֯ʂ • க໋తΤϥʔ͜Ε·Ͱ෮ؼͰ͖ͳ͔ͬͨ❗ • ྫɿଘࡏ͠ͳ͍ؔίʔϧɺએݴͷॏෳͳ Ͳ
͘ଓ͍͖ͯͨ(99%ͷਓࠔͬͯͳ͍) • ଞͷݴޠΑΓக໋తΤϥʔͷൣғ͕ͪΐͬͱ ͍ • ͋·Γeval͕ಘҙͰͳ͍ • க໋తΤϥʔϦΧόϦͰ͖ͳ͍ • σετϥΫλݺΕͳ͍
• ʮന͍ը໘(ಥવࢮ)ʯΛճආ͠ɺจ຺ʹԠͨ͡ Τϥʔը໘Λ͢Δͷ͕ͪΐ͍໘
PHP7͔Βɺக໋తΤϥʔྫ֎ͰϦΧόϦʔ Ͱ͖Δ • \Error ΫϥεΛͱͨ͠Ϋϥε͕ྫ֎Ͱ͛ ΒΕΔ • க໋తͳΤϥʔͷʮେମશ෦ʯ͕ʮྫ֎ʯʹͳ Δ •
ͳͬͯͳ͍ॴ͋Δʢྫɿ࠷ॳͷίʔυͰ ύʔεΤϥʔΩϟονෆೳʣ • ࠷ޙ·ͰΩϟον͞Εͳ͔ͬͨྫ֎ैདྷͷΤ
͜ΕʹΑͬͯ • PHP͕ຯʹෆಘҙͳʮΧοίΠΠ500ʯ͕ग़ ͘͢͠ͳΔʢ͔ͳʣ • ϝλ͍ίʔυΛॻ͍ͨͱ͖ɺଈࢮ͢ΔՄೳੑΛ ݮΒͤΔ(ؾ͕͢Δ) • ίʔϧόοΫؔΛଟ༻͢Δͱ͖ͱ͔ศརʢͦ ͏ʣ
• σʔϞϯͳͲΛॻ͖͘͢ͳΔʢ͔ͳʣ
ྫ <?php try{ ଘࡏ͠ͳ͍ؔ(); }catch(\Excepion $e){ // ௨ৗͷྫ֎͜͜ʹ }catch(\Error $e){
// ৽͍͠ɺΤϥʔʢͷྫ֎ʣ͜͜ʹ } // PHP<7 ͜͜ʹ͘Δ͜ͱෆՄೳ
ҙ • NoticeɺWarningྫ֎ʹʮͳΒͳ͍ʯ • ྫ֎ΛΩϟον͠ͳ͍Ͱऴྃ͢Δͱɺطଘ ίʔυΛյͪ͠Ό͏ • ͭ·Γʮେ౷ҰΤϥʔϋϯυϦϯάʯͰͳ͍ • ࠓ·Ͱ௨Γset_error_handlerͰྫ֎ʹม
Մೳɺ͕ΜΕʂ
ઌऔΓDisΓใɺΤϥʔฤ • PHPerΏΔ;ΘͳͷͰ catch(\Exception $e) ͱ͔͍͏ϫΠϧυΧʔυΛ͍͕ͪ • ҆қʹ\Exception ͷαϒΫϥεͰΤϥʔͷྫ ֎Λੜ͢ͱʮΏΔ;ΘPHPerͷ໋͕Ϡό͍ʯ
• ݁Ռɺ\Exceptionͷ͞ΒʹΫϥεͱͯ͠ \Throwable͕Ͱ͖ͨɻ\Error\Throwable ͷࢠʹɻ
࣮ • ͱ͜ΖͰɺ࣮\ErrorExceptionͱ͍͏ྫ֎ ͢Ͱʹ͋Δ • ʮPHPͷݩ͔Β͋ΔErrorͱɺErrorͱ͍͏৽ ͍͠ྫ֎ΫϥεͱɺErrorExceptionͱ͍͏ྫ ֎Ϋϥε͕ࠞࡏʯ • ͍ͩ͆͆͆͞
• ʢ͜͜Beta1͋ͨΓͰRFC͔Β͍͖ͳΓ༷ ͕͔ΘͬͨͷͰɺ·ͨมΘΔ͔ʣ
ʮࠓޙ༧͞ΕΔະདྷʯ • ʮφϧϗυʂʂࠓޙcatch(\Throwable $e) ͔͚͍͍ͬͯΜͩͶʂʂʯ • ʮ!ʯ • ʢerror_reporting(0)ͬͯॻ͍ͯΔਓ͍Δ ͔Βɺ͋ͳ͕ͪஊͰͳ͍ʢഭਅʣʣ
͍
จ๏ͷՃ • ??ԋࢉࢠ(isset͔Βͷ։์ʣ<=>ԋࢉࢠ • ແ໊ΫϥεͷՃ
??ԋࢉࢠ • ΈΜͳେ͖isset͔Βͷ٫ if(isset($_GET['name'])) $name = $_GET['name']; else $name =
'anonymous'; ! $hoge = (isset($_GET['name'])) ? $_GET['name'] : 'anonymous'; ! $name = $_GET['name'] ?? 'anonymous' ; • ??ະఆٛมʹ৮ͬͯେৎͰ͢ɺศ རʂʂʂʂ
<=> UFOԋࢉࢠ • Rubyͷ͋ΕͰ͢ɺιʔτ͕ศརʹʂʂ <?php $item_list = [ ["id"=>3, "name"=>"uzulla"],
["id"=>2, "name"=>"lestrrat"], ["id"=>10, "name"=>"moznion"] ]; usort($item_list, function ($left, $right) { return $left["id"] <=> $right["id"]; });
ෳΧϥϜࢦఆͰ͖·͢ <?php usort($item_list, function ($left, $right) { return [$left["id"], strlen($left["name"])]
<=> [$right["id"], strlen($right["name"])] ; }); • ͜ΕSQLͷෳORDERͬΆͯ͘ศརͬΆ͍
ແ໊Ϋϥε • ΠϯϥΠϯͰɺଈ࣌ʹΠϯελϯεੜͰ͖Δ • DIͰɺͦͷͰΧδϡΞϧʹΠϯελϯεڍ ಈΛม͑ΒΕͯศར…͔ͳ • (DIͱ͔͔͍ͯ·͢ͷ͕ɺʮਖ਼͍͠DIʯʹ͍ͭ ͯצห͍ͯͩ͘͠͞)
ྫ <?php $app->setLogger( new class extends \My\Logger { public function
emergency( $message, array $context = [] ){ \My\AlertPush($message); parent::emergency($message, $context); } } ); • ͜Ε֦ுͯ͠Δ͚ͲɺѲΓͭͿ࣌͢ͱ͔ʢʣ ʹ͑ͦ͏Ͱ͢Ͷ
༧ޠ͕Ճ • Ϋϥε໊/ΠϯλʔϑΣΠε໊ • ຯʹΠϯύΫτ͕͋Δ • int, float, bool, string,
true, false, null, resource, object, mixed, numeric • Ұ෦ͷWAFʹɺStringͱ͍͏Ϋϥε͕…
PHP7ͷIDEͷରԠ!
͍ • ·͋ɺΦγϟϨʹͳΓ·͢Ͷ • ແ໊Ϋϥε͍·͘ΔͱίʔυδϟϯϓͰ͖ͳ ͘ͳΓͦ͏ͳͷͰ΄Ͳ΄Ͳʹ͢Δ༧ఆͰ͢ • ༧ޠʹΑͬͯຯʹಈ͔ͳ͍ΞϓϦ͕͋Δ…
Γ্͕Γ • ਐΉίϯϙʔωϯτԽ • PSR-7ʢ…͕͜Ε͔Β͘Δʁʣ • ʮϏοάϓϨΠϠʔʯ
ίϯϙʔωϯτԽ • PSR-0,4 ͱComposerͷීٴͰී௨ͷݴޠͬΆ ͘ͳΓ… • ୯ମͷORMɺϧʔλʔɺςϯϓϨʔτɺDI׆ ༻͕׆ൃʹͳΓ… • Symfony,
Aura, Zend Framework • ʮΦϨΦϨWAFେ͖ʂʂʯͳਓʹ࠷ߴ
ʮϑϨʔϜϫʔΫࢮΜͰ͍ͳ͍ʯ • 0͔Β·ΕͨൿͷϑϨʔϜϫʔΫɺڊେ ͳϞϊγϦοΫϑϨʔϜϫʔΫ͔Βͷ٫… ͱɺ͍͏ײ͡Ͱͳ͍ɻ • ݁ہͦΕΒΛ͔ͭͬͨϏοάFW͕ΘΕͯΔ • ͦΕΒͷதͰίϯϙʔωϯτΛ͔͍ͭͬͯͯ ɺ݁ہδϟΠΞϯτϦʔϓൃੜ͢Δ
ͦΜͳࡢࠓɺྲྀߦΓͦ͏ͳPSR-7 • HTTPϝοηʔδΫϥεɺrequest/response • perlͰ͍͏ HTTP::RequestɺJavaͰ͍͏ ServletΈ͍ͨͳͷ͕ཉ͍͠ɺͱ͍͏ྲྀΕʢࠓ ·ͰFW͕Ί͍Ί͍ʹͬͯͨʣ • PHPࣗମͷػೳͰͳ͍͠ɺinterfaceͰ͔͠ͳ
͍
ʮPSRͬͯʁʯ • ༗ࢤʹΑΔɺ۩ମతͳઃܭ༷ͷఏҊ • ΦʔτϩʔυͷϑΝΠϧܗࣜɺϩΨʔAPI • ͋͘·Ͱ༗ࢤͷఏҊͰɺʮ๏ʯͰͳ͍ • ੈلౖΓͷPHPσεϩʔυʹடং͕(ը૾ུ) •
ڈͷࢲͷൃදΛݟ͍ͯͩ͘͞
PSR-7ͷϝϦοτ • PHPಠಛͳɺάϩʔόϧม͞ΘΓ·͘Γੈք ʢ$_GET, $_POSTͳͲʣ͔Βͷ٫(ʁ) • ຯʹ໘ͳ$_FILESͱ͔ΛOOPతʹ৮ΕΔ • ͪΌΜͱ࣮ͨ͠ͳΒɺʮob_*ʯΛۦ͢Δ ඞཁݮΔ(ޙड़)
• ൚༻Mock͕࡞Γ͘͢ͳΓςελϒϧɺαϒ ϦΫΤετͱ͔͍͢͠ʢ͔ʣ • Plack::Middleware Έ͍ͨͳͷ͕ͭ͘ΕΔΑ ͏ʹͳΔͣ • ϦΫΤετͷϩΪϯά͘͢͠ͳΔͣ •
reactPHPͳͲɺPHPͰॻ͔Εͨhttpd͕ॻ͖ ͘͢ͳΔʢؾ͕͢Δʣ
σϝϦοτҙ • ੜ$_POSTɺੜechoͷํ͕͍ • ૉखͰ͞ΘΔʹେੜͳAPIʢWAF͕Ӆṭ͢ ΔͩΖ͏͚Ͳʣ • $_SESSIONʮؚ·Εͳ͍ʯ! • $_POSTʮӅͤͳ͍ʯɺੜecho͢Δͱग़ͪ
Ό͏ɺ؆୯ʹҳͰ͖ΔʢٻΊΒΕΔ੍ࣗ৺ʣ
ڍಈ࣮࣍ୈͳͷͰ… • ༷௨ΓͪΌΜͱ࣮͢Δͷେมͦ͏ • ʮob_*Λීஈ͔Β͔͍ͭ͜ͳ͠ɺόΧͰ͔͍ CSVΛग़ྗ͍ͯ͠Δօ͞·ʯɺΠϯελϯε ʹϨεϙϯεΛͨΊࠐΉࣄʹջٙతͰ͠ΐ͏ɻ ࣮ࡍɺμϝͳ࣮ʮՄೳͰ͢ʯɻ • ʮॻ͖ग़ͯ͠෦ϦμΠϨΫτ͠Α͏ʯ
ʮੈͷதʹapache+mod_php͔͠ͳ͍ਓ ͍ΔΜͰ͢Αʂʯ
My fav WAFͰ͋ΔSlim3ͷPSR-7࣮Ͱ • php://tempΛ͔͍ͭͬͯͨ • PHPΈࠐΈͷετϦʔϜϥούʔ • ΦϯϝϞϦʹอ࣋͠ɺσϑΥϧτͰ2MB Λ͑ΔͱཪͰϑΝΠϧʹॻ͖ग़͢
༨ஊ:"Stream"ͷଟ༻ʹ͍ͭͯ • αΠζ͕༧ͮ͠Β͍bodyΛѻ͏ͨΊʹ Stream͕ΘΕΔࣄ͕ଟ͍༷ • ΧδϡΞϧʹมΛ͍͍ͨPHPerʹ໘͆ • WAFʹӅṭ͞ΕΔͷͰɺීஈҙࣝ͠ͳͯ͘ ྑ͍͕ɺ͕ෆ҆ •
ͪͳΈʹ$HTTP_RAW_POST_DATAPHP7Ͱແ͘ ͳΔɻphp://inputΛ͔ͭ͏͔͠ͳ͍ʢͦͯ͠ ͜ΕmultipartͰ͔ͭ͑ͳ͍ͷͰɺྗۀͰ౷
PSR-7ͷ࣮Λ͍͔ͭ͘ݟͨײ • ݱঢ়WAF͕Ί͍Ί͍ʹ࣮͍ͯ͠Δ • ͳ͔ͳ͔టष͍͜ͱΛ͍ͬͯΔɺΤοδέʔ ε͋Γͦ͏… • ಠࣗContent-typeͱ͔ߟ͑ͯͳ͍Ϡπ͋Δͬ Ά͍ •
͍͖ͳΓ͜ΕΛʹ͢Δͷෆ҆
ʮPSR-7ඞਢ͔ʁʯ • ྫྷ੩ʹ͍͑ɺNo • ৽͍͠ࣄ͕Ͱ͖ΔΘ͚Ͱͳ͍ • ͔͠͠ΦγϟϨ…ςετͦ͢͠͏…͗͠ ͦ͢͏… • ʢࢲੈؒΒͣͳͷͰɺ͜͏͍͏ʹὃ͞Ε
͍͢ʣ
༨ஊ • ʮαʔϒϨοτ͡ΌΜʯʮ͍ʯ • ʮ͜ͷձʹݟ͋;ΕΔํ͍Βͬ͠Ό͍· ͤΜ͔ɺཔΉྑ͍PSR-7࣮Λ࡞ͬͯ͘Εʯ • ʮPHPͰॻ͔Εͨhttpdͷ͕࣌͘Δʂʯʢͱ ͍͏ئʣ
͍
ϓϨΠϠʔͷ • ʮPHPͳΜͯͩΕ͔ͭͬͯͳ͍Ͱ͠ΐ͆͆ ͆ʯ • ʮΠέͯΔاۀPHP͔ͭͬͯΔͧʂʂʯ • ʮ·ͩFacebookཔΈʁ͆͆ʯ
ϝϧΧϦ༷ • YAPCεϙϯαʔͰ͋ΒΕΔ
ಔᮐύʔιϯ
ҧ͏
• chatwork…PHPͰScala…
πΠΩϟεʂ • BUT… ʮେମCͰॻ͍ͯΔʯʢࣾ͞Μஊʣ • ͨͯ͠PHP7ʹҠߦ͢Δͷ͔…ʁ
͍͍ɺ͋ͦ͜PHPͰ͢Αʁ
slack!!!
Slack • https://twitter.com/SlackHQ/status/ 426469205005705217 • PHPslack͔ͭͬͯΔʂʂʢ/index.phpɺ ͕͋ΔͬΆ͍ʂʣ • ʮslackఔʯ·ͰͳΒPHPྑ͍Θ͚Ͱ͢Αɻ •
ʢ·͍͔͋ͭͷΓ͔͑ΔͩΖ͏͚Ͳʂʂʣ • ʢπΠοτ2014/01ࠒʣ
• ͍͔ͭPHPΛʮଔۀʯ͢Δձࣾଟ͍Ͱ͠ΐ ͏ɺΘ͔Δɻ • ͰɺʮάϫοͬͱΛͭ͘ΔʯͷʹPHP ͍ͯͨΓ͠·͢ • ʮෛ࠴ʁෛ࠴͕ͳ͍ݴޠͱʁʯ
ͦͯ͠ະདྷ… • PHPͷσεϩʔυײઌͰݮ͖͍ͬͯͯΔ • ͔͠͠ɺϞμϯͳPHPͲ͜ʹ͍Δͷ͔ʁ • ʮࠓ͔ΒʯPHPΛΔҙຯ͕͋Δͷ͔ʁͱ͍͏ ͝ҙݟ • ʮԿͰ࡞Δ͔ΑΓɺԿΛ࡞Δ͔ͩΖʂʂʯ
• ʮPHP͘Β͍ͳΒͰ͖ΔͰ͠ΐʁʯͰਓूΊ ʢPHP͕Ұ൪͍͠ͱ͍͏Ұ෦ͷ͝ҙݟʣ
https://github.com/blog/2047-language-trends- on-github
༨ஊɿݸਓతͳ࠷͍͔ۙͭ͘ͷଉۤ͠ ͞ • ϞμϯͳWAFɺPSRͳͲͰʮϕετϓϥΫςΟ εʯ͕ߴ·Δ • ʮ͜͏͠ͳ͍ͷඍົʯͱ͍͏෩ை • ʮͬͱྑ͍ख๏ʯͷൃ໌ʮγϯϓϧ͞ʯΛ ԡ͑͞ࠐ·ͳ͍͔ʁ
• Έ͕ݮͬͨͷ͔૿͑ͨͷ͔ྑ͘ղΒͳ͍
࣭ٙԠλΠϜ • ͳʹ͔͍͟͝·͔͢ʁ • ແ͚Ε…
͋ͷਓࠓ
HHVM
3ߦͰղΔHHVM • Facebook࡞ͷɺޓੑ͕ߴ͍PHPϥϯλΠϜ • fastCGIɺ·ͨhttpdαʔόͱͯ͠ಈ࡞ • Hackͱ͍͏PHPΛຐվͨ͠Ϟμϯ෩ݴޠ͕ ͑Δ
HHVM Ͳ͏ͳͬͨʁ • ߴԽͱ͍͑HHVMͩͬͨͷͰʁ • PHP7ʹ͕ฒΕͨʢ·͋ɺPHP7· ͩStableग़ͯͳ͍͚Ͳʣ • Hackͱ͍͏ݴޠʁ •
গͳ͘ͱɺຊͰϚδͰྲྀߦͬͯͳ͍ • ւ֎ͰFBҎ֎Ͱྲྀߦͬͯͳ͍ͷͰ …ʁ
ʔϜ
ݱঢ় • HackݴޠਐԽͯ͠Δ • ଂhttpd͕Ͳ͖ͬͯͨ • όʔδϣϯ݁ߏॱௐʹ্͕͍ͬͯΔ • 3.7>3.8Ͱ5ʙ10%͕͋ͬͨΓͯ͠Δ
ࠓͷॴɺcommitਰ͑ͨΓ͍ͯ͠ ͳ͍ • ίϛολύοͱݟͰݮ͍ͬͯͳ͍
HHVM,PHP7ʹΑΔڝ૪ʹ͍ͭ ͯ • ʢڈҐʣʮHHVM͕ઌ佃ΛΓPHP5.xͷഒ ʹʂʯʢΦΦʔʂ • zend͕ຊؾΛग़ͯ͠ɺPHP7Ͱ͍͍ͭ ͨ • HHVMҾ͖༷͢ʹؤுͬͯΔ
• ʮ݂Ͱ݂Λચ͏ϕϯν߹ઓʯ
ʮͲ͕͍ͬͪͷ͔ʁʯ • PHP7 stable·ͩग़ͯͳ͍ͷͰͳ… • άάΔͱେྔͷαϯϓϧ͕ग़ͯ͘Δ • ߴԽͷख๏͕ҧ͏ͷͰέʔεόΠέʔε • ʮࣗͷίʔυʯͰࢼ͞ͳ͍ͱԿͱݴ͑ͳ͍
ϕϯνϚʔΫɾϓϩύΨϯμ • ͍ΖΜͳਓ͕ʮ͕͍ͬͪ͜ʂʯͱ͍͍ͬͯΔ • ಄ͷάϥϑΛ࠶ܝࡌ
None
None
None
None
None
None
None
ϓϩύΨϯμࢲײ • ʮϊϯνϡʔϯʯͩͱPHP7͕ଟগ͍ϕϯν ͕ଟ͍ • ʮνϡʔϯʯ͢ΔͱHHVM͍ • νϡʔϯͱɺHackԽɺawaitར༻ͳͲ • ·͋ɺPHP5.6͔ΒͷࠩΛݟΕେࠩͳ͍
ԶతʮͲͬͪΛ͏͖͔ʁʯ in 2015 • ։ൃຊ൪Linux͔ʁ • ͍͍͑ → PHP •
͍ → • ผʹʁ → PHP • HackΛ͍͍ͨ → HHVM
ʮຊՈPHPʯͷڧ͞ • HHVM͕PHPʹ͋ΘͤͯɺPHP͕HHVMʹ߹ ΘͤΔٛཧͳ͍ • ʢ͍͍ॴ͚ͩύΫΔ࢟ • ֤छπʔϧɺIDEɺC֦ுຊՈ͕ୈҰ • Hack·ͩPHPStormͷαϙʔτແ͍ʢࠓ
ޙʁʁʣ • ࠓޙͷ֤σΟετϦඪ४ຊՈPHPͩΖ͏
HHVMͷʢݱঢ়ͷʣඍົ͞ • OSXͰʢࠓݱࡏʣϏϧυͰ͖ͳ͍ʢաڈͰ ͖ͨʣ https://github.com/facebook/hhvm/issues/ 5447 ʢBrewͱ͔ʹஆ͔͘ͳ͍ʣ • LinuxͰɺϏϧυ໘ʢಛʹCentOSʣ •
UbuntuόΠφϦ༗Γ • ʮHackΛ͏ʯͱɺྲّྀ͕PHPͱҧ͍͗͢Δ
ͭ·Γ • ʮ·͋ɺຊՈPHPΛ͔͓ͭ͏ʯ • ͔͠͠·ͩ·ͩྲྀಈత • Hack͕IDEαϙʔτ͡·ͬͨΒ͏͔ʂ
ҰԠɺHackͷΞπ͞ • Hack language • asyncʢMysqlmemcacheʣ • Generics • Type
Aliasing • ==> Ͱλ • Type check جຊඞਢ http://docs.hhvm.com/manual/en/ install.hack.bootstrapping.php
HackΛΒͳ͍ਓ͚ɺ==> ʹ͍ͭ ͚ͯͩαϯϓϧ <?hh // strict function l() : (function(int):
int) { $a = 1; return $b ==> $a + $b; } $f = l(); echo $f(2); // => 3 • ΦγϟϨͩ͠ɺʢΑ͘σΟεΒΕΔʣuse͕ෆ ཁ
ૉͳPHPͰॻ͘ͱ͜͏͍͏ίʔυ <?php function l() { $a = 1; return function
($b) use ($a){ return $a + $b; } } $f = l(); echo $f(2); // => 3
ͱ͜ΖͰɺPHP7Ͱʁ <?php declare(strict_types=1); function l(): Closure { $a = 1;
return function (int $b) use ($a) : int{ return $a + $b; } } $f = l(); echo $f(2); // => 3 • ※rc1Ͱuse۟ͷܕએݴ͏͔ͣ͝…
HHVMͷະདྷͲͬͪͩ • ެࣜͳະདྷ͋·Γݟ͑ͳ͍ʁʢPHPRFCΛ ݟΔͱ͔…ʣ • ͜ͷ··ͰϕλʔPHPͱͯ͠ͷ࠲͕ة͏͍ • Ͱ͞ΒʹҾ͖͢ͷ͔ʁ • OSXͰHHVM͕͔ͭ͑ΔΑ͏ʹͯ͠΄͍͠
• xhpͳͲͷ֦ுͰReactͳͲͷJSͱྑ͘ͱ͔ ͷະདྷʁ
͍
㙽ʹ֯ • Έͳ͞ΜPHP͔͍͖ͭͬͯ·͠ΐ͏ • PHPਐԽΛ͚͍ͭͮͯ·͢ • ͜Θ͘ͳ͍Α! • Ζ͏ʂPHPʂʂʂʂ