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チュートリアル (LLまつり版)
Search
Yusuke Ando
August 24, 2013
Programming
37
16k
モダンPHPチュートリアル (LLまつり版)
レガシーなプラクティスを捨ててモダンなコードを。
Yusuke Ando
August 24, 2013
Tweet
Share
More Decks by Yusuke Ando
See All by Yusuke Ando
CakePHP3でアプリ開発
yandod
1
340
Shimokita.Unity パーティクルでエフェクト
yandod
0
760
CakePHP3の明るい未来
yandod
1
210
Testing your app with Selenium on Travis CI
yandod
8
3.1k
Testing your app with Selenium on Travis CI
yandod
0
130
Inputで入力を扱う
yandod
0
660
Detonatorで爆発させる勉強会をした報告
yandod
0
2.4k
Mecanimでアニメーション - Shimokita.Unity
yandod
0
720
パリの街をUnityで駆ける
yandod
1
3.4k
Other Decks in Programming
See All in Programming
103 Early Hints
sugi_0000
1
230
Beyond ORM
77web
5
520
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Security_for_introducing_eBPF
kentatada
0
110
良いユニットテストを書こう
mototakatsu
5
2k
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
CSC305 Lecture 26
javiergs
PRO
0
140
Featured
See All Featured
Making Projects Easy
brettharned
116
5.9k
Building Your Own Lightsaber
phodgson
103
6.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Into the Great Unknown - MozCon
thekraken
33
1.5k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Six Lessons from altMBA
skipperchong
27
3.5k
The Cult of Friendly URLs
andyhume
78
6.1k
Unsuck your backbone
ammeep
669
57k
Statistics for Hackers
jakevdp
796
220k
Become a Pro
speakerdeck
PRO
26
5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Transcript
MMNBUTVSJ!ZBOEP Modern PHP Tutorial d1)1࣌ͷࣝΛࣺͯɺ1)1࣌d
ZBOEP $BOEZ$BOFQIQ ʮ࠙ձϐβൃΞϓϦʯ
1)1ରԠ1BB4 $IFGͰ"84Λࣗಈߏஙɺߋ৽ "84ͱಉ͡ڥΛίετʹ ࣌ؒ༗ਓࢹΦϓγϣϯ 44)TVEPՄೳ͔ͭαϙʔτ༗
1)1 8FCʹಛԽͨ͠εΫϦϓτݴޠ 8FCαʔϏεΛத৺ʹ෯͍ར༻ ඇΤϯδχΞͷར༻ऀଟ͍ ؒҧͬͨϓϥΫςΟε·͍ͬͯΔ
ΞδΣϯμ جૅࣝ ؒҧͬͨϓϥΫςΟε ϞμϯͳϓϥΫςΟε ͬͯΈΑ͏
جૅࣝ
ใͷ୳͠ํ ॳ৺ऀ͚ͷॻ੶๛ ެࣜϚχϡΞϧͷಡΈํ͕େࣄ தʙ্ڃऀ͚ϑϨʔϜϫʔΫ༷ʑ 1)15IF3JHIU8BZ
None
ॻ੶બͼ ༰͕ݹ͘ͳΔ ݱʹ͍ΔஶऀɺϥΠλʔઐͷஶऀ αϯϓϧίʔυͷηΩϡϦςΟ ݁ہԿ͔ͷ߹ΘٕͤʹͳΔ
QIQOFU
QIQOFU ެࣜϚχϡΞϧ ෆஅͷྗͰຊޠԽ͞Ε͍ͯΔ جຊతʹ࠷৽ͷ1)1ʹ४ڌ KQQIQOFUͱ͍͏ϛϥʔ͋Δ Կނ͔ σβΠϯ͕ϦχϡʔΞϧ༧ఆ
৽σβΠϯ
ҠߦΨΠυ
ऴྃͨ͠όʔδϣϯ 1)1 ʹऴྃࡁΈ 1)1 ʹऴྃࡁΈ 1)1 ʹऴྃࡁΈ
1)1 ʹऴྃࡁΈ 1)1 ʹऴྃ༧ఆ
ݱߦόʔδϣϯ 1)1 ໊લۭؒ Ϋϩʔδϟ
Ԇ੩తଋറ -4# 1)1 "SSBZ4IPSU4ZOUBY USBJU ϏϧτΠϯαʔό 1)1 δΣωϨʔλ pOBMMZ
ϙΠϯτ 1)1Ҏ͔߱ͭͯ1)1ͱݺΕͯ ͍ͨػೳΛؚΜͰ͍Δ 1)1த৺ͷݱͰ͋ͬͯ1)1Ҏ߱ ͷػೳͷ׆༻ेʹਐΜͰ͍ͳ͍
Ϟμϯ1)1 ݹ͍ϓϥΫςΟεΛഇ͠ɺ ਖ਼͍͠1)1Λॻ͜͏
ϨΨγʔ1)1ɺɹۦஞͯ͠Δʜ ͜ͷੈ͔ΒʜɹҰߦʜΒͣ
ؒҧͬͨϓϥΫςΟε photo by toyohara
ʑͷؒҧ͍ JOD $3 -' SFHJTUFS@HMPCBMT TBGF@NPEF NBHJD@RVPUF ! WBS
NZTRM@DPOOFDU SFRVJSF@PODF 1&"3 ؆୯ Nڃ ෳࡶ Nڃ ෳࡶ Nڃ ෳࡶ Nڃ
ϑΝΠϧ JOD $3 -'
ϑΝΠϧͷ࠷ޙͷ লུͰ͖Δ ͷޙͷۭന͕͔͍ͬ )551ϔομͷ੍ޚෆೳɺṖͷۭߦ େྔͷϑΝΠϧʹฆΕΔͱհ
Ṗͷۭߦ <?php //৭ʑͳίʔυ $view->render(); ?>
͜ͷԿॲ͔ʹۭߦ͕ʜ
͜ΕͰΑ͍ <?php //৭ʑͳίʔυ $view->render(); QIQͷ෦ͷۭߦग़ྗ͞Εͳ͍
JOD$3 -' ֦ுࢠJODͷϑΝΠϧʹϥΠϒϥϦΛ ஔ͘ѱश ίʔυ࿙Ӯͷةݥ͋Γ վߦίʔυ-'ʹ౷Ұ͖͢
1)1ͷҨ࢈ SFHJTUFS@HMPCBMT TBGF@NPEF NBHJD@RVPUF@HQD SVOUJNF ഇࢭ͞ΕΔͷͰೋͱ͍͚ͬͯͳ͍
ෆશͳ001ͷ໊ ! WBS
! Τϥʔ੍ԋࢉࢠ ͔ͭͯྫ֎͕ଘࡏ͠ͳ͔ͬͨ σόοάΛࠔʹ͢Δհͳଘࡏ దʹίʔσΟϯά͢Εແ༻ͷଘࡏ
WBS QVCMJDQSJWBUFͳͲ͕ແ͔ͬͨࠒͷଘࡏ QVCMJDQSJWBUFΛهड़͢Δ͖ TUBUJDదʹઃఆ͢Δ
໌ࣔతͳࢀর͠ ͔ͭͯϝϞϦઅͷςΫχοΫ ݱࡏৗʹࢀরʹͳΔͷͰෆཁ ͋͑ͯίϐʔ͍ͨ࣌͠ʹDMPOF
1)1 <?php class A { var $foo = 1;
} $obj =& new A(); $obj2 =& $obj; $obj2->foo = 2; echo $obj->foo;
ෆཁ 1)1 <?php class A { public $foo = 1;
} $obj = new A(); $obj2 = $obj; $obj2->foo = 2; echo $obj->foo;
ݹ͍ϥΠϒϥϦ NZTRM@DPOOFDU SFRVJSF@PODF 1&"3ͷޡ༻
NZTRM@DPOOFDU ݹདྷΑΓΘΕ͖ͯͨؔ 1)1͔Βඇਪɺഇࢭ༧ఆ NZTRMJ@DPOOFDU1%0Λ͏
SFRVJSF@PODF ผϑΝΠϧͷϥΠϒϥϦͷಡΈࠐΈ ͱʹ͔͋͘Ε͜ΕಡΈࠐΈ·͘Γ͕ͪ BVUPMPBEػߏ͕ग़དྷͨͷͰෆཁʹ
1&"3 ོ͔ͭͯΛތͬͨϥΠϒϥϦ܊ ݫ֨ͳެࣜνϟωϧ ݱଘ͢ΔϑϨʔϜϫʔΫͷૅ Πϯετʔϥʔ͕͍ʹ͍͘ ίϐʔ͞Εվม͞Εɺߋ৽ෆೳʹ
1&"3 ิ ݱࡏ1)16OJU4NBSUZͳͲ1&"3ϕʔ εͷϥΠϒϥϦ׆ൃ ઃఆ1ZSVTͳͲʹΑΔରॲ๏͋Δ ਖ਼͘͠ར༻͠ɺదʹӡ༻͞Ε͍ͯΕ ͳ͍ ޡ༻͞ΕΔ͜ͱ
͋ͳͨͷίʔυʹ͜͏͍ ͬͨ༰͕ଟ͍ͱةݥ
ϨΨγʔ1)1ɺɹۦஞͯ͠Δʜ ͜ͷੈ͔ΒʜɹҰߦʜΒͣ
ϞμϯͳϓϥΫςΟε
None
1)15IF3JHIU8BZ 4MJN'SBNFXPSLͷ࡞ऀ+PTIࢯ͕ൃىਓ 1)1ͷϕετϓϥΫςΟε (JU)VC্Ͱ֤ݴޠʹ༁͞Εͨ ͜ͷ༰Λक͍ͬͯΕϞμϯ
ͷϓϥΫςΟε ͡Ίʹ ίʔσΟϯάελΠϧ ݴޠ༷ ґଘؔͷཧ ίʔσΟϯάʹؔ͢Δ׳श σʔλϕʔε ηΩϡϦςΟ ςετ ֤छαʔόʔͷσϓϩΠ
Ωϟογϡ ใݯ ίϛϡχςΟ
͡Ίʹ 1)1Ҏ߱Λ͏ .BD049ͷ1)1ݹ͍IPNFCSFX 8JOEPXT৭ʑ͋Γ͗͢ 7BHSBOUศར
7BHSBOU 7JSUVBM#PYΛΠϯετʔϧ 7BHSBOUΛΠϯετʔϧ ͖ͳ7BHSBOUpMFΛDMPOF WBHSBOUVQ શʹઃఆ͞ΕͨԾϚγϯ͕ىಈ
ίʔσΟϯάελΠϧ 143143143 1)1$PEF4OJ⒎FS 1)1$PEJOH4UBOEBSET'JYFS
None
େࣄͳͱ͜Ζ ϑΝΠϧ໊ɺύε ΠϯσϯτɺϒϨʔεͷҐஔ 1)14UPSNͳͲͷ*%&ͰݕࠪՄೳ
ݴޠ༷ͷϙΠϯτ 001ແ໊໊ؔલۭؒτϨΠτ Ϋϩʔδϟ ϝλϓϩάϥϛϯά 41-$-* 9%FCVH
DMBTTͷڭࣨ
ґଘؔͷཧ $PNQPTFSϓϩδΣΫτґଘؔ 1&"3γεςϜશମͷґଘؔ ࠷৽൛ͷߋ৽੬ऑੑνΣοΫ ϥΠϒϥϦQBDLBHJTUͰ୳ͤΑ͍
$PNQPTFS DVSMTIUUQTHFUDPNQPTFSPSH JOTUBMMFScQIQ DPNQPTFSKTPO DPNQPTFSJOTUBMM SFRVJSFbWFOEPSBVUPMPBEQIQ` SFRVJSF͜Ε͚ͩ
ίʔσΟϯά جຊ ࣌ࠁ%BUF5JNF σβΠϯύλʔϯ'BDUPSZ4JOHMFUPOϑ ϩϯτίϯτϩʔϥ.7$ ྫ֎ॲཧ
جຊ ൺֱԋࢉࢠ JGFMTF TXJUDI γϯάϧΫΦʔτɺμϒϧΫΦʔτ ࡾ߲ԋࢉࢠ
σʔλϕʔε 1%0 NZTRM@DPOOFDU ഇࢭ༧ఆ 1%0൚༻త͔ͭߴػೳ όΠϯυΛઈର͏
όΠϯυ
ηΩϡϦςΟ ύεϫʔυͷϋογϡQBTTXPSE@IBTI σʔλͷϑΟϧλϦϯά αχλΠζ όϦσʔγϣϯ 3FHJTUFS(MPCBMT1)1Ͱഇࢭ
݁ɿಙؙຊΛങ͏
ςετ Ϣχοτςετ1)16OJU ػೳςετ4FMFOJVN ৼۦಈ։ൃ#%%#FIBU1)14QFD
None
σϓϩΠ 1BB4 OHJOYQIQGQNলϝϞϦ "QBDIFNPE@QIQ 1IJOH$BQJTUSBOP$IFG $* +FOLJOT 5FBNDJUZ
None
None
Ωϟογϡ όΠτίʔυΩϟογϡ "1$9$BDIF;FOE0QUJNJ[FS8JO$BDIF ΦϒδΣΫτΩϟογϡ "1$.FNDBDIF3FEJT
5IF3JHIU8BZ த্ڃऀʹͱͬͯͨΓલͷ༰ ͷࢼߦࡨޡͷੵͷ݁Ռ ॾࣄ͋ͬͯɺैͬͯଛແ͍
ͬͯΈΑ͏ʂ
࡞Δͷ 7BHSBOUͰಈ͘ $PNQPTFSͰϥΠϒϥϦΛಋೖ 5XJUUFS͔Βใऔಘ
7BHSBOU 7JSUVBM#PY7BHSBOU IUUQTHJUIVCDPNZBOEPEQIQ OHJOYWBHSBOUTBNQMF HJUDMPOF WBHSBOUVQ
DPNQPTFSKTPO WBHSBOUTTI DEWBHSBOU@EBUBTBOECPY DPNQPTFSKTPOΛهड़͢Δ ࣗಈͰखಈͰͰ͖Δ
DPNQPTFSKTPO { "name": "llmatsuri/sample", "authors": [ { "name": "yando", "email":
"
[email protected]
" } ], "require": { "dg/twitter-php": "*" } }
DPNQPTFSKTPO ΄͍͠ϥΠϒϥϦΛݕࡧͯ͠ࢦఆ͢Δ 8FCͰίϚϯυͰݕࡧͰ͖Δ ࣮1&"3ΠϯετʔϧͰ͖Δ ࠷ޙʹDPNQPTFSJOTUBMMͰ·ͱΊͯ%-
DPNQPTFSJOTUBMM vagrant@precise64:/vagrant_data$ composer install Loading composer repositories with package information
Installing dependencies (including require-dev) - Installing dg/twitter-php (v3.1) Loading from cache Writing lock file Generating autoload files
JOTUBMM͢Δͱ DPNQPTFSMPDL͕ੜ͞ΕΔ WFOEPSҎԼʹϥΠϒϥϦ͕%-͞ΕΔ WFOEPSҎԼʹΦʔτϩʔμ͕ஔ
༻ޙ
BVUPMPBE BVUPMPBEQIQ͚ͩΛSFRVJSF͢Δ ඞཁͳ࣌ʹ֤ΫϥεΛࣗಈͰಡΈࠐΉ ೋͱSFRVJSF@PODFΛॻ͔ͳ͍ ϑϨʔϜϫʔΫ͕ಡΈࠐΉ߹͋Δ
JOEFYQIQ <?php require_once 'vendor/autoload.php'; $twitter = new Twitter(); ͜Ε͚ͩͰ5XJUUFSΫϥεΛࣗಈతʹ WFOEPSEHUXJUUFSQIQTSD͔ΒಡΈࠐΉʂ
Τϥʔʁ 5XJUUFSΫϥείϯγϡʔϚΩʔͱ ίϯγϡʔϚγʔΫϨοτ͕ඞཁΒ͍͠
EFWUXJUUFSDPNBQQT αΠϯΞοϓ ΞϓϦΛ࡞ ੜ͞ΕͨΩʔใΛίϐͬͯ͏
औಘ <?php require_once 'vendor/autoload.php'; $twitter = new Twitter( 'aaaa', 'bbbb',
'cccc', 'dddd' ); $info = $twitter->loadUserInfo('yando'); var_dump($info->status->text);
͓͓ʂ
͋ͱ ϥΠϒϥϦΛDPNQPTFSKTPOՃ DPNQPTFSVQEBUFͰߋ৽ WFOEPSΛίϛοτ͠ͳ͍ σϓϩΠ࣌ʹJOTUBMMͰWFOEPSΛ࠶ੜ
͞Βʹ 143Λक͍ͬͯΕࣗ࡞ΫϥεͰ BVUPMPBEʹରԠͰ͖Δ 1&"3ͳͲDPNQPTFSͰΠϯετʔϧ ίʔυϦϙδτϦ͕εοΩϦ
࣭ʁ