ã³ãŒãã®è§£é
ããããããããã¹ãŠã©ã®ããã«æ©èœãããã«ã€ããŠè©±ãåã«ã1ã€ã®ç°¡åãªäŸãèŠãŠã¿ãŸãããã æ°ããããã°ã©ãã³ã°èšèªãããããšãæ³åããŠã¿ãŠãã ããïŒååã¯äœã§ããïŒã èšèªã¯éåžžã«ã·ã³ãã«ã§ãïŒ
- åè¡ã¯åŒ ã
- ååŒã¯ã³ãã³ã ïŒæŒç®åïŒã§æ§æãããŸã
- ã³ãã³ããæäœããå€ ïŒãªãã©ã³ãïŒã®æ°ã
äŸïŒ
set a 1
set b 2
add abc
print c
ããã¯åçŽãªèšèªãªã®ã§ããã®ã³ãŒãã¯ç»é¢3ã«ã®ã¿è¡šç€ºããããšå®å šã«æ³å®ã§ããŸããsetæŒç®åã¯å€æ°ãåãåããããã«çªå·ãå²ãåœãŠãŸãïŒPHPã®
$a=1
ããã«ïŒã
add
ã¹ããŒãã¡ã³ãã¯ãè¿œå ãã2ã€ã®å€æ°ãåãã3çªç®ã®å€æ°ã«çµæãä¿åããŸãã
print
ã¹ããŒãã¡ã³ãã¯ããã衚瀺ããŸãã
次ã«ãåãåŒããèªã¿åããæŒç®åãšãªãã©ã³ããèŠã€ããŠãç¹å®ã®æŒç®åã«å¿ããŠãããã䜿çšããŠäœããå®è¡ããããã°ã©ã ãäœæããŸãããã ãªã¹ã1ãèŠããšãããããã«ãããã¯PHPã§ã®å®è£ ã¯éåžžã«ç°¡åã§ãã
ãªã¹ã1
01. <?php 02. 03. $lines = file($argv[1]); 04. 05. $linenr = 0; 06. foreach ($lines as $line) { 07. $linenr++; 08. $operands = explode(" ", trim($line)); 09. $command = array_shift($operands); 10. 11. switch ($command) { 12. case 'set' : 13. $vars[$operands[0]] = $operands[1]; 14. break; 15. case 'add' : 16. $vars[$operands[2]] = $vars[$operands[0]] + $vars[$operands[1]]; 17. break; 18. case 'print' : 19. print $vars[$operands[0]] . "\n"; 20. break; 21. default : 22. throw new Exception(sprintf("Unknown command in line %s\n", $linenr)); 23. } 24. }
ããã¯éåžžã«ã·ã³ãã«ãªããã°ã©ã ã§ãããæ°ããèšèªã§æ¬¡ã®Webã¢ããªã±ãŒã·ã§ã³ãäœæããå¿ èŠã¯ãããŸããã ãããããã®äŸã¯ãæ°ããèšèªãäœæãããã®èšèªãèªã¿åã£ãŠå®è¡ã§ããããã°ã©ã ãååŸããããšãããã«ç°¡åããç解ããã®ã«åœ¹ç«ã¡ãŸãã ãã®å ŽåããœãŒã¹ãã¡ã€ã«ã1è¡ãã€èªã¿åããçŸåšã®æŒç®åã«å¿ããŠã³ãŒããå®è¡ããŸãã ã¢ããªã±ãŒã·ã§ã³ãå®è¡ããããã«ãã¢ã»ã³ãã©ãŒãŸãã¯ãã€ããªã³ãŒãã«å€æããå¿ èŠã¯ãããŸãããæ¢ã«ããŸãæ©èœããŠããŸãã ããã°ã©ã ãå®è¡ãããã®æ¹æ³ã¯ã解éãšåŒã°ããŸãã ããšãã°ãåºæ¬ããã°ã©ã ã¯å€ãã®å Žåããã®æ¹æ³ã§å®è¡ãããŸããååŒãèªã¿åãããããã«é«ã¬ãã«ã¢ãŒãã§å®è¡ãããŸãã
ããããå€ãã®åé¡ããããŸãã ãããã®1ã€ã¯ãåæ§ã®èšèªããã»ããµã®äœæã¯éåžžã«ç°¡åã§ãããæ°ããèšèªã¯éåžžã«ãã£ããå®è¡ãããããšã§ãã çµå±ãåè¡ãåŠçãããã§ãã¯ããå¿ èŠããããŸãïŒ
- ã©ã®ãªãã¬ãŒã¿ãŒãå®è¡ããå¿ èŠããããŸããïŒ
- ããã¯æ£ããæŒç®åã§ããïŒ
- 圌ã¯é©åãªæ°ã®ãªãã©ã³ããæã£ãŠããŸããïŒ
ããããä»ã®ã¿ã¹ã¯ãå¿ããŠã¯ãªããŸããã ããšãã°ãsetã¹ããŒãã¡ã³ãã¯å€æ°ã®ã¿æ°å€ãŸãã¯æååå€ãå²ãåœãŠãããšãã§ããŸããïŒ ãŸãã¯ãä»ã®å€æ°ã®å€ãïŒ ååŒãé©åã«åŠçããã«ã¯ãããããã¹ãŠã®è³ªåã«çããå¿ èŠããããŸãã
set 1
4ãæžã蟌ããšã©ããªããŸããïŒ ã€ãŸãããã®æ¹æ³ã§ã¯ãé«éå®è¡ã¢ããªã±ãŒã·ã§ã³ãäœæããããšã¯ã»ãšãã©äžå¯èœã§ãã
ãããããã®ããšãã«ãããããã解éã«ã¯å©ç¹ããããŸããå€æŽã®ãã³ã«ããã°ã©ã ãããã«å®è¡ã§ããŸãã 泚æïŒPHPã¹ã¯ãªããã§äœããå€æŽãããšãããã«å®è¡ããŠå€æŽã確èªã§ããŸãã ããã¯ãPHPãã€ã³ã¿ãŒããªã¿ãŒèšèªã§ããããšãæå³ããŸããïŒ çŸæç¹ã§ã¯ãã¯ããšä»®å®ããŸãã PHPã¹ã¯ãªããã¯ãä»®æ³ã®åçŽãªèšèªã®ããã«è§£éãããŸãã ãããã次ã®ã»ã¯ã·ã§ã³ã§ã¯ãããã«æ»ããŸãïŒ
ãã©ã³ã¹ã³ã³ãã€ã«
ããã°ã©ã ããé«éãã«ããã«ã¯ã©ãããã°ããã§ããïŒ ããã¯ããŸããŸãªæ¹æ³ã§å®è¡ã§ããŸãã Facebookã§éçºããããã®ãã¡ã®1ã€ã¯HipHopãšåŒã°ããŸãïŒçŸåšäœ¿çšãããŠããHHVMã§ã¯ãªãããå€ããHipHopã·ã¹ãã ãæå³ããŸãïŒã HipHopã¯ãããèšèªïŒPHPïŒãå¥ã®èšèªïŒC ++ïŒã«å€æããŸããã å€æçµæã¯ãC ++ã³ã³ãã€ã©ã䜿çšããŠãã€ããªã³ãŒãã«å€æã§ããŸãã 圌ã®ã³ã³ãã¥ãŒã¿ãŒã¯ãã€ã³ã¿ãŒããªã¿ãŒã®åœ¢ã§è¿œå ã®è² è·ãªãã«ç解ããŠå®è¡ããããšãã§ããŸãã ãã®çµæãèšå€§ãªéã®ã³ã³ãã¥ãŒãã£ã³ã°ãªãœãŒã¹ãç¯çŽãããã¢ããªã±ãŒã·ã§ã³ã®å®è¡é床ãå€§å¹ ã«åäžããŸãã
ãã®æ¹æ³ã¯ããœãŒã¹ãããœãŒã¹ãžã®ã³ã³ãã€ã«ããã©ã³ã¹ã³ã³ãã€ã«ããŸãã¯ãã©ã³ã¹ã³ã³ãã€ã«ãšãåŒã°ããŸãã å®éã«ã¯ããã€ããªã³ãŒããžã®ã³ã³ãã€ã«ã§ã¯ãªããæ¢åã®ã³ã³ãã€ã©ã«ãã£ãŠãã·ã³ã³ãŒãã«ã³ã³ãã€ã«ã§ãããã®ãžã®å€æã§ãã
ãã©ã³ã¹ã³ã³ãã€ã«ã䜿çšãããšããã€ããªã³ãŒããçŽæ¥å®è¡ã§ãããããããã©ãŒãã³ã¹ãåäžããŸãã ãã ãããã®ã¡ãœããã«ã¯æ¬ ç¹ããããŸããã³ãŒããå®è¡ããåã«ãæåã«ãã©ã³ã¹ã³ã³ãã€ã«ãè¡ãã次ã«å®éã®ã³ã³ãã€ã«ãè¡ãå¿ èŠããããŸãã ãã ããããã¯ã¢ããªã±ãŒã·ã§ã³ã«å€æŽãå ããããå Žåãã€ãŸãéçºäžã«ã®ã¿è¡ãå¿ èŠããããŸãã
ãã©ã³ã¹ã³ã³ãã€ã«ã¯ãããŒãèšèªãããåçŽãã€åçã«ããããã«ã䜿çšãããŸãã ããšãã°ããã©ãŠã¶ã¯LESSãSASSãSCSSã§èšè¿°ãããã³ãŒããç解ããŸããã ãããããã®åŸããã©ãŠã¶ãç解ã§ããCSSã«çœ®ãæããããšãã§ããŸãã CSSã¯ä¿å®ãç°¡åã§ãããè¿œå ã§ãã©ã³ã¹ã³ã³ãã€ã«ããå¿ èŠããããŸãã
ç·šé
ãã¹ãŠãããã«éãåäœããããã«ã¯ããã©ã³ã¹ã³ã³ãã€ã«ã®æ®µéãåãé€ãå¿ èŠããããŸãã ã€ãŸããç§ãã¡ã®èšèªãããã«ãã€ããªã³ãŒãã«ã³ã³ãã€ã«ãã解éããã©ã³ã¹ã³ã³ãã€ã«ã®åœ¢ã§è¿œå ã®è² è·ããããã«ããã«å®è¡ã§ããŸãã
æ®å¿µãªãããã³ã³ãã€ã©ãæžãããšã¯ãã³ã³ãã¥ãŒã¿ãŒãµã€ãšã³ã¹ã§æãé£ããã¿ã¹ã¯ã®1ã€ã§ãã ããšãã°ããã€ããªã³ãŒãã«ã³ã³ãã€ã«ããå Žåã32ãããLinuxã64ãããWindowsããŸãã¯äžè¬çãªOS Xã§å®è¡ããã³ã³ãã¥ãŒã¿ãŒãæ€èšããå¿ èŠããããŸããã解éãããã¹ã¯ãªããã¯ã©ãã§ãç°¡åã«å®è¡ã§ããŸãã PHPã®ããã«ãã¹ã¯ãªãããã©ãã§å®è¡ãããããå¿é ããå¿ èŠã¯ãããŸããã ç¹å®ã®OSåãã®ã³ãŒããååšããå ŽåããããŸãããä»ã®ã·ã¹ãã ã§ã¹ã¯ãªãããå®è¡ããããšã¯ã§ããŸããããããã¯ã€ã³ã¿ãŒããªã¿ãŒã®åé¡ã§ã¯ãããŸããã
ãããããã©ã³ã¹ã³ã³ãã€ã«ã®æ®µéããªãããŠããã³ã³ãã€ã«ããéããããšã¯ã§ããŸããã ããšãã°ãCïŒã³ã³ãã€ã«ãããèšèªïŒã§æžããã倧ããªããã°ã©ã ã¯ãã»ãŒ1æéã³ã³ãã€ã«ã§ããŸãã PHPã§ã¢ããªã±ãŒã·ã§ã³ãäœæããå€æŽãæ©èœãããã©ããã確èªãããŸã§ããã«10ååŸ ã€å¿ èŠããããšæ³åããŠãã ããã
æåãå°œãããŠ
解éã®å®è¡ã«æéãããããã³ã³ãã€ã«ãå®è£ ãé£ãããéçºã«æéããããå ŽåãPHPãPythonãRubyãªã©ã®èšèªã¯ã©ã®ããã«æ©èœããŸããïŒ åœŒãã¯ããªãéãã§ãïŒ
ããã¯ã解éãšã³ã³ãã€ã«ã®äž¡æ¹ã䜿çšããããã§ãã ãããã©ããªããèŠãŠã¿ãŸãããã
æ¶ç©ºã®èšèªããã€ããªã³ãŒãã«çŽæ¥å€æããã®ã§ã¯ãªããããã«éåžžã«ãã䌌ããã®ïŒããã€ãã³ãŒãããšåŒã°ããïŒã«å€æã§ãããšãããã©ãã§ããããã ãã®ãã€ãã³ãŒããã³ã³ãã¥ãŒã¿ãŒã®åäœã«éåžžã«è¿ãå Žåããã®è§£éã¯éåžžã«é«éã«ãªããŸãïŒããšãã°ã1ç§ãããæ°çŸäžã®ãã€ãã³ãŒãïŒã ããã«ãããã¢ããªã±ãŒã·ã§ã³ã¯ã³ã³ãã€ã«ããããã®ãšã»ãŒåãé床ã«ãªããã€ã³ã¿ãŒããªã¿ãŒèšèªã®ãã¹ãŠã®å©ç¹ãä¿æãããŸãã æãéèŠãªããšã¯ãå€æŽããšã«ã¹ã¯ãªãããã³ã³ãã€ã«ããå¿ èŠããªãããšã§ãã
ãšãŠãé åçã§ãã å®éãå€ãã®èšèªã¯åæ§ã®æ¹æ³ã§åäœããŸã-PHPãRubyãPythonãããã«ã¯Javaã ãœãŒã¹ã³ãŒãã®è¡ãé çªã«èªã¿åã£ãŠè§£éãã代ããã«ããããã®èšèªã¯ç°ãªãã¢ãããŒãã䜿çšããŸãã
- æé 1.ã¹ã¯ãªããïŒPHPïŒãå®å šã«ã¡ã¢ãªã«èªã¿èŸŒã¿ãŸãã
- ã¹ããã2.ã¹ã¯ãªãããå®å šã«ãã€ãã³ãŒãã«å€æ/ã³ã³ãã€ã«ããŸãã
- ã¹ããã3.ã€ã³ã¿ãŒããªã¿ãŒïŒPHPïŒã䜿çšããŠãã€ãã³ãŒããå®è¡ããŸãã
å®éãããã«å€ãã®ã¹ãããããããå®éã«ã¯ããã»ã¹å šäœãã¯ããã«è€éã§ãã ãã ããäžè¬ã«ã説æãããŠãã3ã€ã®æé ã¯ãã³ãã³ãã©ã€ã³ããã¹ã¯ãªãããå®è¡ããããWebãµãŒããŒãä»ããŠèŠæ±ãå®è¡ããã®ã«ååã§ãã
ããã»ã¹ã¯ç°¡åã«æé©åã§ããŸããWebãµãŒããŒãèµ·åããåãªã¯ãšã¹ãã
index.php
ã¹ã¯ãªãããå®è¡ãããšããŸãã ã¡ã¢ãªã«æ¯åããŒãããã®ã¯ãªãã§ããïŒ ãªã¯ãšã¹ãããšã«ãã°ããå€æã§ããããã«ããã¡ã€ã«ããã£ãã·ã¥ããããšããå§ãããŸãã
å¥ã®æé©åïŒãã€ãã³ãŒããçæããåŸãåŸç¶ã®ãã¹ãŠã®ãªã¯ãšã¹ãã«äœ¿çšã§ããŸãã ãããã£ãŠãããããã£ãã·ã¥ã§ããŸãïŒæãéèŠãªããšã¯ããœãŒã¹ãã¡ã€ã«ãå€æŽããããšãã«ããã€ãã³ãŒããåã³ã³ãã€ã«ãããããšã確èªããŠãã ããïŒã ããã¯ãPHPã®OPCacheæ¡åŒµæ©èœã®ããã«ããªãã³ãŒããã£ãã·ã¥ãè¡ãããšãšãŸã£ããåãã§ããã³ã³ãã€ã«ãããã¹ã¯ãªããã¯ãéå°ãªããŠã³ããŒãããã€ãã³ãŒããžã®ã³ã³ãã€ã«ãªãã«åŸç¶ã®ãªã¯ãšã¹ãã§ãã°ããå®è¡ã§ããããã«ãã£ãã·ã¥ãããŸãã
æåŸã«ãé«éåã®æåŸã®ã¹ãããã¯ãPHPã€ã³ã¿ãŒããªã¿ãŒã«ãããã€ãã³ãŒãã®å®è¡ã§ãã 次ã®ããŒãã§ã¯ããããåŸæ¥ã®éèš³è ãšæ¯èŒããŸãã æ··ä¹±ãé¿ããããããã®ãããªãã€ãã³ãŒãã€ã³ã¿ãŒããªã¿ãŒã¯ããä»®æ³ãã·ã³ããšåŒã°ããŸããããã¯ãããçšåºŠãŸã§ãã·ã³ïŒã³ã³ãã¥ãŒã¿ãŒïŒã®äœæ¥ãã³ããŒããããã§ãã ããããVirtualBoxãVMwareãªã©ã®ã³ã³ãã¥ãŒã¿ãŒã§å®è¡ãããŠããä»®æ³ãã·ã³ãšæ··åããªãã§ãã ããã ããã¯ãJavaã®äžçã®JVMïŒJavaä»®æ³ãã·ã³ïŒãPHPã®äžçã®HHVMïŒHipHopä»®æ³ãã·ã³ïŒã®ãããªãã®ã§ãã PythonãšRubyã«ã¯ç¬èªã®ä»®æ³ãã·ã³ããããŸãã ããæå³ã§ã¯ããããã¯ãã¹ãŠéåžžã«å°éçã§çç£çãªãã€ãã³ãŒãã€ã³ã¿ãŒããªã¿ãŒã§ãã
åVMã¯ãç¹å®ã®èšèªã«ãã£ãŠçæãããç¬èªã®ãã€ãã³ãŒããå®è¡ããŸãããäºãã«äºææ§ããããŸããã Python VMã§PHPãã€ãã³ãŒããå®è¡ããããšã¯ã§ããŸãããéã®å Žåãåæ§ã§ãã ãã ããPHPã¹ã¯ãªããããã€ãã³ãŒãã«ã³ã³ãã€ã«ããããã°ã©ã ãäœæããããšã¯çè«çã«ã¯å¯èœã§ãããããã¯Python VMã«ãã£ãŠç解ãããŸãã ãããã£ãŠãçè«çã«ã¯ãPythonã§PHPã¹ã¯ãªãããå®è¡ã§ããŸãïŒæ·±å»ãªèª²é¡ã§ãïŒïŒã
ãã€ãã³ãŒã
ãã€ãã³ãŒãã¯ã©ã®ããã«èŠããåäœããŸããïŒ 2ã€ã®äŸãèŠãŠã¿ãŸãããã PHPã³ãŒããååŸããŸãã
$a = 3; echo "hello world"; print $a + 1;
3v4l.orgã䜿çšããããVLDæ¡åŒµæ©èœãã€ã³ã¹ããŒã«ããããšã«ããããã®ãã€ãã³ãŒãã衚瀺ã§ããŸãã 次ã®ãã®ãåŸãããŸãã
次ã«ãåæ§ã®Pythonã®äŸãåãäžããŸãã
def foobar(): a = 1 print "hello world", print a + 4
Pythonã¯ãªãã³ãŒããçŽæ¥çæã§ããŸã©pythonïŒ
dis.disïŒfuncïŒ ïŒ
2ã€ã®åçŽãªã¹ã¯ãªãããšãã®ãã€ãã³ãŒãããããŸãã ãã€ãã³ãŒãã¯ãèšäºã®åé ã§ãäœæãããèšèªã«äŒŒãŠããããšã«æ³šæããŠãã ãããåè¡ã¯ãä»»æã®æ°ã®ãªãã©ã³ããæã€æŒç®åã§ãã PHPãã€ãã³ãŒãã§ã¯ãæ¥é èŸãå€æ°ã«è¿œå ãããŸãïŒãããã£ãŠã0ã¯å€æ°0ãæå³ããŸãã$ aå€æ°ã䜿çšããããšã¯éèŠã§ã¯ãããŸãããã³ã³ãã€ã«äžãå€æ°åã¯å€ã倱ããæ°å€ã«å€æãããŸãã ããã«ãããä»®æ³ãã·ã³ã«ããåŠçãä¿é²ããã³å éãããŸãã å¿ èŠãªããã§ãã¯ãã®ã»ãšãã©ã¯ã³ã³ãã€ã«æ®µéã§å®è¡ãããŸããããã«ãããä»®æ³ãã·ã³ããè² è·ãåãé€ãããé床ãåäžããŸãã
ãã€ãã³ãŒãã¯åçŽãªåœä»€ã§æ§æãããŠããããã解éã¯éåžžã«é«éã§ãã ã€ã³ã¿ããªã¿èšèªã®ååŒã§åŠçããå¿ èŠãããæ°åã®ãã€ããªåœä»€ã®ä»£ããã«ãååŒã®ãã€ãã³ãŒãã«ã¯æ°çŸã®åœä»€ããããŸãïŒããã«å°ãªãå ŽåããããŸãïŒã ãããã£ãŠãä»®æ³ãã·ã³ã¯ã€ã³ã¿ãŒããªã¿ãŒèšèªãããã¯ããã«é«éã«å®è¡ãããŸãã
èšãæããã°ãä»®æ³å¥³æ§ã¯2ã€ã®äžçã®ãã¹ãŠãæ倧éã«æŽ»çšããŸããã ãœãŒã¹ãããã€ãã³ãŒãã«ã³ã³ãã€ã«ããå¿ èŠããããŸããããã®ããã»ã¹ã¯é«éã§ééçã§ãã ãããŠããã€ãã³ãŒããåä¿¡ããåŸãä»®æ³ãã·ã³ã¯äžå¿ èŠãªãªãŒããŒããããªãã«è¿ éãã€å¹ççã«ããã解éããŸãã ãã®çµæãé«æ§èœã®ã¢ããªã±ãŒã·ã§ã³ãã§ããŸããã
ãœãŒã¹ãããã€ãã³ãŒããž
çæããããã€ãã³ãŒããå¹ççã«å®è¡ã§ããããã«ãªã£ãã®ã§ããœãŒã¹ã³ãŒãããã®ãã€ãã³ãŒãã«ã³ã³ãã€ã«ããã¿ã¹ã¯ã¯æ®ããŸãã
次ã®PHPåŒãæ€èšããŠãã ããã
$a = 1; $a=1; $a = 1;
ãããã¯ãã¹ãŠçããåœãŠã¯ãŸããåããã€ãã³ãŒãã«å€æããå¿ èŠããããŸãã ããããããããã©ã®ããã«èªã¿ãŸããïŒ å®éãç¬èªã®ã€ã³ã¿ãŒããªã¿ãŒã§ã¯ãã³ãã³ãã解æããã¹ããŒã¹ã§åºåããŸãã ã€ãŸããã€ã³ãã³ããã¹ããŒã¹ã1è¡ã§ãã©ã±ããã2è¡ã§æãè¿ããªã©ã䜿çšã§ããPHPãšã¯ç°ãªããããã°ã©ããŒã¯ã³ãŒããåãã¹ã¿ã€ã«ã§èšè¿°ããå¿ èŠããããŸãããŸããã³ã³ãã€ã©ãŒã¯ãœãŒã¹ãå€æããããšããŸãããŒã¯ã³å ã®ã³ãŒãã ãã®ããã»ã¹ã¯ãåå¥è§£æãŸãã¯ããŒã¯ã³åãšåŒã°ããŸãã
ã¬ãã·ã³
ããŒã¯ã³åïŒåå¥è§£æïŒã¯ããœãŒã¹PHPã³ãŒãã-ãã®æå³ãç解ããã«-ããŒã¯ã³ã®é·ããªã¹ãã«å€æããããšã§æ§æãããŸãã ããã¯è€éãªããã»ã¹ã§ãããPHPã§ã¯åæ§ã®ããšãéåžžã«ç°¡åã«è¡ããŸãã ãªã¹ã2ã®ã³ãŒãã¯æ¬¡ã®çµæãçæããŸãã
T_OPEN_TAG <?php T_VARIABLE $a T_WHITESPACE = T_WHITESPACE T_LNUMBER 3 ; T_WHITESPACE T_ECHO echo T_WHITESPACE T_CONSTANT_ENCAPSED_STRING "hello world" ;
æååå€ã¯ããŒã¯ã³ã«å€æãããŸãïŒ
- <ïŒphpã¯T_OPEN_TAGããŒã¯ã³ã«å€æããã
- $ aã¯ã$ aã®å€ãå«ãT_VARIABLEããŒã¯ã³ã«å€æãããŸãã
ããŒã¯ãã€ã¶ãŒã¯ãã³ãŒããèªã¿åããšãã«ãæåaãä»ãã$èšå·ãæ€åºãããšããããèªèããŸãããã®åŸãä»»æã®æ°ã®æåãšæ°åãç¶ããããšãã§ããŸãã çªå·ã¯T_LNUMBERãšããŠããŒã¯ã³åããã1ããã以äžã«ããããšãã§ããŸãã ããŒã¯ã³åã«ãããããã°ã©ããŒã«åŒ·å¶ããããšãªããããæ§é åããã圢åŒã§ãœãŒã¹ã³ãŒããæ瀺ã§ããŸãã ãããããã§ã«è¿°ã¹ãããã«ãããŒã¯ãã€ã¶ãŒã¯ããŒã¯ã³ã®æå³ãç解ããŠããŸããã çæ³çã«ã¯ã$ a = 1ãš1 = $ aã®äž¡æ¹ãããŒã¯ã³åããŸãã 次ã®ããŒãã§ã¯ã解ææ¹æ³ãåŠç¿ããŸã-å€ãããŒã¯ã³ã®ã¹ããªãŒã ã«èšå®ããŸãã
解æ
ããŒã¯ã³ã解æãããšããèšèªãæ§æããããã€ãã®ãã«ãŒã«ãã«åŸãå¿ èŠããããŸãã ããšãã°ãã«ãŒã«ãããå ŽåããããŸããããã°ã©ã ã§æåã«æ€åºãããããŒã¯ã³ã¯T_OPEN_TAGïŒ<ïŒPhpã«å¯Ÿå¿ïŒã§ãªããã°ãªããŸããã
å¥ã®å¯èœãªã«ãŒã«ïŒå²ãåœãŠã¯ãä»»æã®T_VARIABLEã®åŸã«=æåã次ã«T_LNUMBERãT_VARIABLEããŸãã¯T_CONSTANT_ENCAPSED_STRINGãå«ããããšãã§ããŸãã ã€ãŸãã$ a = 1ããŸãã¯$ a = $ bããŸãã¯$ a = 'foobar'ãèš±å¯ããŸããã1 = $ aã¯èš±å¯ããŸããã ããŒãµãŒããã©ã®ã«ãŒã«ãæºãããªãäžé£ã®ããŒã¯ã³ãæ€åºãããšãæ§æãšã©ãŒãèªåçã«çæãããŸãã äžè¬ã«ã解æã¯èšèªãå®çŸ©ããæ§æèŠåãäœæã§ããããã«ããããã»ã¹ã§ãã
PHP ã§äœ¿çšãããŠããã«ãŒã«ã®ãªã¹ããåç §ããŠãã ããã PHPã¹ã¯ãªãããæ§æèŠåãæºãããŠããå Žåãæ§æãæ£ããã ãã§ãªããæå³ãããããšã確èªããããã«è¿œå ã®ãã§ãã¯ãå®è¡ãããŸãïŒ
public abstract final final private class foo() {}
ã®å®çŸ©ã¯æ£ãããããããŸãããã芳ç¹ããã¯æå³ããããŸããPHP ããŒã¯ã³åãšè§£æã¯æ±ãã«ããããã»ã¹ã§ãããå€ãã®å ŽåããµãŒãããŒãã£ã®ã¢ããªã±ãŒã·ã§ã³ãããããå®è¡ããããã«äœ¿çšãããŸãã ãã°ãã°flexãbisonãªã©ã®ããŒã«ã䜿çšããŸãïŒPHPã§ãïŒã ãŸãããã©ã³ã¹ã³ã³ãã€ã©ãšèŠãªãããšãã§ããŸããã«ãŒã«ãCã³ãŒãã«å€æããPHPãã³ã³ãã€ã«ãããšèªåçã«ã³ã³ãã€ã«ãããŸãã
ããŒãµãŒãšããŒã¯ãã€ã¶ãŒã¯ä»ã®åéã§åœ¹ç«ã¡ãŸãã ããšãã°ãããŒã¿ããŒã¹å ã®SQLåŒã解æããããã«äœ¿çšãããå€ãã®ããŒãµãŒãšããŒã¯ãã€ã¶ãŒãPHPã§èšè¿°ãããŠããŸãã Doctrineã®ãªããžã§ã¯ããªã¬ãŒã·ã§ãã«ããããŒã«ã¯ãDQLåŒçšã®ç¬èªã®ããŒãµãŒãšãDQLãSQLã«å€æããããã®ããã©ã³ã¹ã³ã³ãã€ã©ãŒãããããŸãã Twigãå«ãå€ãã®ãã³ãã¬ãŒããšã³ãžã³ã¯ãç¬èªã®ããŒã¯ãã€ã¶ãŒãšããŒãµãŒã䜿çšããŠããã³ãã¬ãŒããã¡ã€ã«ãPHPã¹ã¯ãªããã«ãã³ã³ãã€ã«ãããŸãã å®éããããã®ãšã³ãžã³ã¯ãã©ã³ã¹ã³ã³ãã€ã©ã§ããããŸãïŒ
æœè±¡æ§æããªãŒ
èšèªãããŒã¯ã³åããŠè§£æããåŸããã€ãã³ãŒããçæã§ããŸãã PHP 5.6ãŸã§ã¯ã解æäžã«çæãããŸããã ãã ããããã»ã¹ã«å¥ã®ã¹ããŒãžãè¿œå ãããšãããŒãµãŒã«ãã€ãã³ãŒãã§ã¯ãªããããããæœè±¡æ§æããªãŒïŒASTïŒãçæãããããšãã§ããŸãã ããã¯ãããã°ã©ã å šäœãæœè±¡çã«è¡šçŸãããããªãŒæ§é ã§ãã ASTã¯ããã€ãã³ãŒãã®çæãåçŽåããã ãã§ãªããå€æããåã«ããªãŒãå€æŽããããšãã§ããŸãã ããªãŒã¯åžžã«ç¹å¥ãªæ¹æ³ã§çæãããŸãã ããªãŒããŒãã¯ifåŒã§ãããå¿ ç¶çã«ãã®äžã«3ã€ã®èŠçŽ ããããŸãã
- æåã®ãã®ã«ã¯æ¡ä»¶ãå«ãŸããŸãïŒ
$a == true
ïŒã - 2çªç®ã«ã¯ã
true
æ¡ä»¶ãæºããããå Žåã«å®è¡ããå¿ èŠãããåŒãå«ãŸããŠãtrue
ã - 3çªç®ã«ã¯ã
false
æ¡ä»¶ãæºããããå Žåã«å®è¡ããå¿ èŠãããåŒïŒelse
åŒïŒãå«ãŸããŸãã
else
æ¬ ããŠããå Žåã§ãã3ã€ã®èŠçŽ ãããã3çªç®ã®èŠçŽ ã ãã空ã«ãªããŸãã
ãã®çµæãããã°ã©ã ããã€ãã³ãŒãã«å€æããåã«ãæžãçŽããããšãã§ããŸãã ããã¯ã³ãŒããæé©åããããã«æã 䜿çšãããŸãã éçºè ãã«ãŒãå ã§å€æ°ãç¹°ãè¿ãåèšç®ããå€æ°ã®å€ãåžžã«åãã§ããããšãããã£ãŠããå Žåããªããã£ãã€ã¶ãŒã¯ASTãæžãæããŠãæ¯ååèšç®ããå¿ èŠã®ãªãäžæå€æ°ãäœæã§ããŸãã ããªãŒã¯ã³ãŒãã®å°ããªåç·šæã«äœ¿çšã§ãããããäžèŠã«ãªã£ãå€æ°ã®åé€ãªã©ãé«éã«åäœããŸããããã¯åžžã«å¯èœã§ãããšã¯éããŸããããããã°ã©ã å šäœã®ããªãŒãããå Žåããã®ãããªãã§ãã¯ãšæé©åã¯ã¯ããã«ç°¡åã«å®è¡ã§ããŸãã ASTå ã§ã¯ãå€æ°ã䜿çšãããåã«å®£èšãããŠãããã©ããããŸãã¯æ¡ä»¶ãããã¯ã§å²ãåœãŠã䜿çšãããŠãããã©ããã確èªã§ããŸãïŒ
if ($a = 1) {}
ïŒã ãŸããæœåšçã«ãšã©ãŒã®ããæ§é ãæ€åºãããå Žåã¯ãèŠåãçºè¡ããŸãã ããªãŒã䜿çšããŠãæ å ±ã»ãã¥ãªãã£ã®èŠ³ç¹ããã³ãŒããåæããã¹ã¯ãªããã®å®è¡äžã«ãŠãŒã¶ãŒã«èŠåããããšãã§ããŸãã
ããã¯éçåæãšåŒã°ããŸããããã«ãããéçºè ã調åã®ãšããå®å šã§é«éãªã³ãŒããäœæããã®ã«åœ¹ç«ã€æ°ããæ©èœãæé©åãæ€èšŒã·ã¹ãã ãäœæã§ããŸãã
PHP 7.0ã§ã¯ã解æäžã«ASTãçæããæ°ãã解æãšã³ãžã³ïŒZend 3.0ïŒãå°å ¥ãããŸããã ããã¯ååæ°é®®ã§ãããããããŸããããè¡ãããšã¯ã§ããŸããã ãããããã®ååšã®åãªãäºå®ã¯ãè¿ãå°æ¥ã«ããŸããŸãªæ©äŒã®åºçŸãæåŸ ã§ããããšãæå³ããŸãã
token_get_all()
é¢æ°ã¯ãææžåãããŠããªãæ°ããå®æ°TOKEN_PARSEããã§ã«åãå ¥ããŠããŸããããã¯å°æ¥ãããŒã¯ã³ã ãã§ãªã解æãããASTãè¿ãããã«äœ¿çšã§ããŸãã php-astãªã©ã®ãµãŒãããŒãã£ã®æ¡åŒµæ©èœã䜿çšãããšãPHPã§ããªãŒãçŽæ¥è¡šç€ºããã³ç·šéã§ããŸãã Zendãšã³ãžã³ãšASTå®è£ ã®å®å šãªåèšèšã«ãããPHPã¯ããŸããŸãªæ°ãã課é¡ã«çŽé¢ããŸãã
Jit
ASTããçæãããé«åºŠã«æé©åããããã€ãã³ãŒããå®è¡ããä»®æ³ãã·ã³ã«å ããŠãé床ãäžããå¥ã®ææ³ããããŸãã ããããããã¯å®è£ ãæãé£ãããã®ã®1ã€ã§ãã
ã¢ããªã±ãŒã·ã§ã³ã¯ã©ã®ããã«å®è¡ãããŠããŸããïŒ ã»ããã¢ããã«ã¯å€ãã®æéãããããŸããããšãã°ããã¬ãŒã ã¯ãŒã¯ã®èµ·åãã«ãŒãã®è§£æãç°å¢å€æ°ã®åŠçãªã©ãå¿ èŠã§ãããããã®æé ããã¹ãŠå®äºããåŸãããã°ã©ã ã¯éåžžå®è¡ãããŠããŸããã , - . , , (, ) ? , , , . , , , , .
. -, . JIT- (just-in-time, ). . , - , , . â . , . , .
JIT- . ; , ; , . JIT' : , .
JIT' , . JIT' runtime , . , JIT' .
HHVM, JIT-: PHP- ( Hack) -, HHVM. , ; , . -, .
PHP 7 JIT-, . , , JIT-. , PHP 7 !