Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PhpStormの静的解析

 PhpStormの静的解析

JetBrains IDEといえば超強力リファクタリング機能!
なのに何故なんだ、何故PHPだとうまく動かない?
その原因はやはり動的型付け言語故の問題があった。

それでもPhpStorm動き方の癖を覚えればバッチリ安心して使える。
癖を覚えてリファクタリングをガンガン使っていこう!

そんな内容をPhpStormの静的解析機能を紹介しながら語りました。

B989cc865d53d8e26fdadac99727113c?s=128

Satoshi Kawashima

July 25, 2017
Tweet

Transcript

  1. ઒ౡܛ(.01FQBCP *OD  1IQ4UPSNͷ੩తղੳ

  2. ΤϯδχΞ ઒ౡܛ!CBSJF ຊࣾࣄۀ෦+6(&.νʔϜ IUUQOB[POPIJUPKVHFNKQ

  3. ΞδΣϯμ w1IQ4UPSNͷ੩తղੳ w֤ػೳͷ঺հ wϑΝΠϧߏ଄ͷղੳDMBTTͷߏ଄ղੳఆٛͱݺͼग़ؔ͠܎ͷղੳ σʔλϑϩʔͷղੳϦϑΝΫλϦϯά w1IQ4UPSNͷ੩తղੳͷݶք w·ͱΊ

  4. 1IQ4UPSNͷ੩తղੳ

  5. 1IQ4UPSNͷ੩తղੳ wγϯλοΫενΣοΫ wίʔυϑΥʔϚοτνΣοΫ wΠϯςϯγϣϯˍΠϯεϖΫγϣϯʢજࡏతͳόάνΣοΫʣ wΞϓϦέʔγϣϯ෼ੳ w֤छఆٛͷղੳDMBTTͷܧঝؔ܎ͷղੳݺͼग़ؔ͠܎ͷղੳ

  6. $male = new Male();
 $male->greeting();
 
 $robot = new Robot();


    $robot->greeting();
 
 $str = 'string desuyo';
 $str->greeting();
 
 $male->greeting(); 1IQ4UPSNͷܕਪ࿦ class Male
 {
 public function greeting()
 {
 echo '͜Μʹͪ͸';
 }
 } class Robot
 {
 public function greeting()
 {
 echo 'ίϯχνϋ';
 }
 } %FDMBSBUJPO %FDMBSBUJPO NBMF͸.BMFDMBTTͷ ΦϒδΣΫτ΍ʂ SPCPU͸3PCPUDMBTTͷ ΦϒδΣΫτ΍ʂ TUSJOH͔ΒNFUIPEݺͼग़͠ ͳΜͯͰ͖΁ΜͰʂ 'JOE6TBHF
  7. ϑΝΠϧߏ଄ͷղੳ

  8. 'JMF4USVDUVSF ˡϑΝΠϧͷಡΈࠐΈ SFRVJSF@PODFͱ͔ ˡGVODUJPOͷఆٛ ˡDMBTTͷఆٛ ˡNFUIPEͷఆٛ ˡQSPQFSUZͷఆٛ ˡ൒ಁ໌ͳͷ͸਌DMBTT͔Βܧঝͨ͠΋ͷ

  9. DMBTTͷܧঝؔ܎ͷղੳ

  10. DMBTTͷܧঝؔ܎ͷղੳ $MBTT" $MBTT# $MBTT$ "CTUSBDU$MBTT" *OUFSGBDF" *OUFSGBDF# *OUFSGBDF$ FYUFOET FYUFOET

    FYUFOET JNQMFNFOUT JNQMFNFOUT 5SBJU" VTF
  11. DMBTTͷܧঝؔ܎ͷղੳ wDMBTTͷܧঝؔ܎Λղੳͯ͘͠ΕΔ w͔ͳΓͷਫ਼౓Ͱղੳͯ͘͠ΕΔ wಈతܕ෇͚ݴޠͰ΋DMBTTߏ଄͸͍͍ͩͨ੩తʹܾఆ͢Δ wಉ໊ͷDMBTT͕ෳ਺͋Δ৔߹͸আ͘ wԾʹ͋ͬͨ৔߹͸ܧঝؔ܎ΛҰҙʹఆΊΑ͏ͱͯ͠ղੳ݁Ռ͕͓͔ ͘͠ͳΔ

  12. 5ZQF)JFSBSDIZ wDMBTTͷܧঝπϦʔ͕Ұ໨Ͱ෼͔Δ wJOUFSGBDFͱUSBJU͸ग़ͯ͘͠Εͳ͍ wJOUFSGBDF͸ɺJOUFSGBDFࢦఆͨ͠ ্Ͱ5ZQF)JFSBSDIZ࣮ߦ͔ɺ *NQMFNFOUBUJPO wUSBJU͸'JOE6TBHF

  13. DMBTTͷߏ଄ղੳ w5ZQF)JFSBSDIZDMBTTͷܧঝؔ܎ͷղੳ w*NQMFNFOUBUJPOͦͷDMBTTJOUFSGBDFΛܧঝ࣮૷͍ͯ͠ΔDMBTTΛ දࣔ͢Δ w4VQFS.FUIPEΦʔόʔϥΠυ͍ͯ͠ΔNFUIPEͷɺ਌DMBTTͷఆٛ ΁ඈͿ w.FUIPE)JFSBSDIZΦʔόʔϥΠυ͍ͯ͠ΔNFUIPEͷɺؔ܎Λղੳ ͢Δ

  14. ఆٛͱݺͼग़ؔ͠܎ͷղੳ

  15. %FDMBSBUJPOͱ'JOE6TBHF w%FDMBSBUJPOఆٛݩ΁δϟϯϓ wม਺ɺGVODUJPOɺDMBTTɺDPOTU͍͍ͩͨԿʹͰ΋࢖͑Δ wಉ໊GVODUJPOɺDMBTT͕ͳ͍ͳΒਫ਼౓͸ߴ͍ w'JOE6TBHFݺͼग़͠ݩ΁δϟϯϓ wม਺ɺGVODUJPOɺDMBTTɺDPOTU͍͍ͩͨԿʹͰ΋࢖͑Δ wDMBTTͷQSPQFSUZʹ࢖͏ͱ͔ͳΓศར w1)1ͷಛੑ্ɺਫ਼౓͸௿͍ʢεϥΠυޙ൒Ͱ৮Ε·͢ʣ

  16. %FDMBSBUJPOͱ'JOE6TBHF function greeting($target)
 {
 $str = '͜Μʹͪ͸';
 
 $str =

    'Hello, ';
 
 echo $str . $target;
 } %FDMBSBUJPO 'JOE6TBHF
  17. %FDMBSBUJPOͱ'JOE6TBHF function hogehoge()
 {
 echo 'hoge';
 } hogehoge(); %FDMBSBUJPO 'JOE6TBHF

    function hogehoge()
 {
 echo 'hoge';
 } hogehoge(); hogehoge(); hogehoge();
  18. abstract class Human
 {
 public function greeting()
 {
 echo 'Hello';


    }
 } %FDMBSBUJPOͱ'JOE6TBHF $male = new Male();
 $male->greeting();
 
 $female = new Female();
 $female->greeting(); class Male extends Human
 {
 public function greeting()
 {
 echo '͜Μʹͪ͸';
 }
 } class Female extends Human
 {
 } %FDMBSBUJPO %FDMBSBUJPO 'JOE6TBHF 'JOE6TBHF
  19. $BMM)JFSBSDIZ wݺͼग़ؔ͠܎ΛҰؾʹղੳ͢Δ w%FDMBSBUJPOͱ'JOE6TBHFΛͻͨ͢Β܁Γฦͯ͘͠ΕΔΑ͏ͳΠ ϝʔδ wݺͼग़ؔ͠܎ΛҰؾʹඈͿ৔߹΍ɺͦ͜΁ࢸΔ·Ͱͷܦ࿏Λௐ΂Δͷ ʹศར

  20. $BMM)JFSBSDIZ ͻͨ͢Βݺͼग़͠ݩΛ୳͢ ͻͨ͢ΒఆٛݩΛ୳͢

  21. σʔλϑϩʔͷղੳ

  22. "OBMZ[F%BUB'MPX5P'SPN wର৅ͷσʔλ͕ͲΜͳܦ࿏͕དྷͨͷ͔ɺͲΜͳܦ࿏Ͱ࢖ΘΕ͍ͯ͘ͷ ͔ʢσʔλϑϩʔʣΛ௥͍͔͚Δػೳ wม਺ͱࣜΛ૬खʹ࢖༻͢ΔΒ͍͠

  23. "OBMZ[F%BUB'MPX5Pͷ৔߹ class Male extends Human
 {
 private $data;
 
 public

    function __construct($data)
 {
 $this->data = $data;
 $this->data->hoge();
 
 parent::__construct('male');
 }
 } function makeModel()
 {
 $dsn = 'phptype://xxxxxxxxxxxxx';
 return new HogeModel($dsn);
 } $fuga = new Fuga();
 $mdl = makeModel();
 
 $fuga->setHuman($mdl); class Fuga
 {
 public function setHuman($mdl)
 {
 $this->male = new Male($mdl);
 }
 }
  24. ͜Μͳͷ͕ग़ͯ͘Δ

  25. ϦϑΝΫλϦϯά

  26. ϦϑΝΫλϦϯά w͍͍ͩͨͷఆٛΛ؆୯ʹมߋͰ͖Δ wม਺GVODUJPODMBTTͷ໊લม͑Δ wҾ਺ͷ਺Λ૿΍ͨ͠Γɺॱ൪ม͑ͨΓͰ͖Δ wίʔυΛผϝιου΁੾Γग़͢ wܧঝؔ܎಺෦ͰఆٛΛࣗ༝ʹҠಈͰ͖Δ wݺͼग़͠ݩશͯͷίʔυ΋मਖ਼ͯ͘͠ΕΔ

  27. 3FOBNF class Robot
 {
 public static function greeting()
 {
 //

    ...
 }
 }
 
 $robot = new Robot();
 
 Robot::greeting(); class Android
 {
 public static function greeting()
 {
 // ...
 }
 }
 
 $robot = new Android();
 
 Android::greeting(); OFX͍ͯ͠ΔՕॴΛࣗಈͰमਖ਼ TUBUJDGVODUJPOݺͼग़͠Օॴ΋ ࣗಈͰमਖ਼ ɾDMBTT໊Λมߋ
  28. $IBOHF4JHOBUVSF function hoge($a, $b)
 {
 return $a + $b;
 }


    
 hoge(1, 3); function hoge($b, $a, $c)
 {
 return $a + $b;
 }
 
 hoge(3, 1, 'fuga'); ɾҾ਺ͷॱংʢBͱCʣΛมߋ ɾDΛ௥ՃʢσϑΥϧτ`GVHB`ʣ ݺͼग़͠ݩͷҾ਺ॱΛ ม͑ͯ͘ΕΔ ৽͍͠Ҿ਺ʹσϑΥϧτ ͰೖΕΔ஋ΛܾΊΒΕΔ
  29. &YUSBDUܥ abstract class Human
 {
 private $name;
 
 public function

    __construct($age, $address, $name)
 {
 $name = 'hoge';
 
 $data['age'] = $age;
 $data['address'] = $address;
 }
 
 private function setData($age, $address)
 {
 $data['age'] = $age;
 $data['address'] = $address;
 return $data;
 }
 public function greeting()
 {
 echo '͜Μʹͪ͸';
 } } &YUSBDU'JFME ʢϑΟʔϧυ΁੾Γग़͠ʣ &YUSBDU1BSBNFUFS ʢҾ਺΁੾Γग़͠ʣ &YUSBDU.FUIPE ʢผNFUIPE΁੾Γग़͠ʣ JOUFSGBDF4QFBLBCMF*OUFSGBDF \ QVCMJDGVODUJPOTQFBL  ^ &YUSBDU*OUFSGBDF ʢΠϯλʔϑΣʔεͷ੾Γग़͠ʣ
  30. 1VTI.FNCFST%PXO1VMM.FNCFST6Q abstract class Human
 {
 public function speak()
 {
 echo

    'hoge';
 }
 } class Male extends Human
 { QVCMJDGVODUJPOTQFBL  \ FDIPbIPHF` ^ ^ 1VTI.FNCFST%PXO ʢϝϯόఆٛΛܧঝઌ΁Ҡಈʣ 1VMM.FNCFST6Q ʢϝϯόఆٛΛܧঝݩ΁Ҡಈʣ
  31. 1IQ4UPSNͷ੩తղੳͷݶք

  32. 1IQ4UPSNͷ੩తղੳʹ͸ݶք͕͋Δ w࣮ߦ࣌ʹม਺ͷܕ͕ܾఆ͢Δݴޠނɺ੩తղੳʹ͸ݶք͕͋Δ wղੳ݁Ռ͕৴༻Ͱ͖ͳ͍ػೳ͸ଟ͍ɺಛʹ'JOE6TBHF wϊΠζ͕ೖΔʢղੳ݁Ռʹ༨ܭͳ΋ͷ͕͍ࠞͬͯ͟Δʣ w࿙Ε͕͋Δʢग़Δ΂͖͸ͣͷ΍͕ͭग़ͯ͜ͳ͍ʣ

  33. 'JOE6TBHFʹґଘ͢Δػೳ͸ଟ͍ w$BMM)JFSBSDIZݺͼग़͠ݩΛҰؾʹղੳ͢Δ w"OBMZ[F%BUB'MPX5P'SPNର৅ͷม਺ͷσʔλϑϩʔΛ௥͍͔͚ Δ w3FOBNF.PWFDMBTTͷ໊લΛม͑ͯɺݺͼग़͠ݩΛमਖ਼͢Δ w$IBOHF4JHOBUVSFNFUIPEͷҾ਺ఆٛΛม͑ͯɺݺͼग़͠ݩΛमਖ਼ ͢Δ w.BLF4UBUJDNFUIPEΛTUBUJDఆٛʹม͑ͯɺݺͼग़͠ݩΛमਖ਼͢Δ

  34. ͦΕͰ΋࢖ͬͯཉ͍͠

  35. 1IQ4UPSNͷ'JOE6TBHFͷڍಈΛ஌Ζ͏ wͲ͜·ͰͳΒ҆શʹ࢖͑Δ͔஌ͬͯ΄͍͠ wͲ͏͢Ε͹҆શʹ࢖͑ΔΑ͏ʹͳΔͷ͔஌ͬͯ΄͍͠ w͋ͨ͜͜ΓΛݴٴ͍ͯ͠Δެࣜͷࢿྉ͸ͳ͍ʢ๻ͷ஌ΔݶΓ w๻ͷ࢖༻ܦݧʹجͮ͘ղੳ݁ՌͰɺ׬ᘳͳ΋ͷͰ͸͋Γ·ͤΜ

  36. ର৅Λݶఆ͢Δ άϩʔόϧε ίʔϓͷม਺ ϩʔΧϧεί ʔϓͷม਺ GVODUJPO DMBTT QVCMJD QSPQFSUZ QSJWBUF

    QSPUFDUFE QSPQFSUZ QVCMJD NFUIPE QSJWBUF QSPUFDUFE NFUIPE %FDMBSBUJP O 'JOE 6TBHF
  37. ϩʔΧϧείʔϓͷม਺ͷ'JOE6TBHF function greeting($target)
 {
 $str = '͜Μʹͪ͸ɺ';
 $target .= '͞Μɻ';


    
 echo $str . $target;
 } %FDMBSBUJPO 'JOE6TBHF ˞جຊతʹ࿙Ε΋ɺϊΠζ΋ͳ͍
  38. GVODUJPOͷ'JOE6TBHF ˞جຊతʹ࿙Ε͸ͳ͍ ˞ಉ໊ͷGVODUJPO͕ͳ͚Ε͹શͯͷݺͼग़͠ݩ͕ಛఆͰ͖ΔʢϊΠζ͕ࠞ͟Βͳ͍ʣ function hogehoge()
 {
 echo 'hoge';
 } hogehoge();

    %FDMBSBUJPO 'JOE6TBHF function hogehoge()
 {
 echo 'hoge';
 } hogehoge(); hogehoge(); hogehoge();
  39. DMBTTͷ'JOE6TBHF DMBTT)PHF  \ ^ DMBTT)PHF  \ ^ IPHFOFX)PHF

     %FDMBSBUJPO 'JOE6TBHF ˞جຊతʹ࿙Ε͸ͳ͍ ˞ಉ໊ͷDMBTT͕ͳ͚Ε͹શͯͷݺͼग़͠ݩ͕ಛఆͰ͖ΔʢϊΠζ͕ࠞ͟Βͳ͍ʣ IPHFOFX)PHF  )PHFTPNF.FUIPE  )PHFTPNF.FUIPE 
  40. QSJWBUFQSPUFDUFE QSPQFSUZNFUIPEͷ'JOE6TBHF class Male extends Human
 {
 public function __construct()


    {
 parent::__construct('Male');
 }
 
 public function greeting()
 {
 echo $this->name;
 }
 } abstract class Human
 {
 protected $name;
 
 public function __construct($name)
 {
 $this->name = $name;
 }
 } %FDMBSBUJPO 'JOE6TBHF ˞ಉ໊ͷDMBTT͕ͳ͚Ε͹࿙Ε΋ϊΠζ΋ͳ͍ ˞ಉ໊ͷDMBTT͕͋Δͱ͓͔͘͠ͳΔ
  41. ͜͜·Ͱͷ·ͱΊ άϩʔόϧε ίʔϓͷม਺ ϩʔΧϧεί ʔϓͷม਺ GVODUJPO DMBTT QVCMJD QSPQFSUZ QSJWBUF

    QSPUFDUFE QSPQFSUZ QVCMJD NFUIPE QSJWBUF QSPUFDUFE NFUIPE %FDMBSBUJP O ̋ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ̋
 ʢ˞̍ʣ 'JOE 6TBHF ̋ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ̋
 ʢ˞̍ʣ ̋
 ʢ˞̍ʣ ˞̍ɿಉ໊ͷGVODUJPODMBTTఆ͕ٛͳ͚Ε͹େৎ෉
  42. ͜͜·Ͱͷ·ͱΊ άϩʔόϧε ίʔϓͷม਺ ϩʔΧϧεί ʔϓͷม਺ GVODUJPO DMBTT QVCMJD QSPQFSUZ QSJWBUF

    QSPUFDUFE QSPQFSUZ QVCMJD NFUIPE QSJWBUF QSPUFDUFE NFUIPE %FDMBSBUJP O ̋ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ̋
 ʢ˞̍ʣ 'JOE 6TBHF ̋ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ̋
 ʢ˞̍ʣ ̋
 ʢ˞̍ʣ ˞̍ɿಉ໊ͷGVODUJPODMBTTఆ͕ٛͳ͚Ε͹େৎ෉ ͜͜Β΁Μ͕໰୊͕ൃੜ͠΍͍͢ʂʂ ˞࿦֎
  43. Կނɺղੳʹࣦഊ͢Δͷ͔ʁ

  44. ܕਪ࿦ʹࣦഊͯ͠Δ͔Β

  45. Կނ'JOE6TBHF͕ಇ͔ͳ͍ͷ͔ʁ wQVCMJDQSPQFSUZNFUIPEͷΞΫηε͸εςʔτϝϯτͰ֬ఆ͢Δ wϑΝΠϧείʔϓΛ·ͨ͗͏Δ wϑΝΠϧείʔϓΛ·͙ͨͱجຊతʹܕਪ࿦Ͱ͖ͳ͍ $male = new Male();
 $male->greeting();
 


    speak($male); function speak($male)
 {
 $male->greeting();
 } class Male
 {
 public function greeting()
 {
 echo 'Hello';
 }
 } NBMF͸.BMFDMBTTͷ ΦϒδΣΫτ΍ʂ ͜Εͳʹʁʁʁʁʁ
  46. 'JOE6TBHFͷڍಈΛ֮͑Δ͜ͱ͸ɺ ܕਪ࿦ͷڍಈΛ֮͑Δࣄ

  47. ਤࣔ͢Δͱ GVODUJPODMBTTͷߏ଄ղੳ ม਺ͷܕਪ࿦ ݺͼग़ؔ͠܎ͷղੳ σʔλϑϩʔղੳ ϦϑΝΫλϦϯά ಉ໊ͷGVODUJPODMBTT͕ ͳ͚Ε͹΄΅׬ᘳ ͍Ζ͍ΖؾΛ͚ͭͳ͍ͱ ͙͢μϝʹͳΔ

  48. ܕਪ࿦ͷڍಈΛ֮͑Α͏

  49. ม਺ͷܕਪ࿦ wϩʔΧϧείʔϓͷม਺ͷܕਪ࿦ wҾ਺ͷܕਪ࿦ w໭Γ஋ͷܕਪ࿦ wQSPQFSUZͷܕਪ࿦ wάϩʔόϧείʔϓͷม਺ͷܕਪ࿦

  50. ϩʔΧϧείʔϓͷม਺ͷܕਪ࿦ w୅ೖ͞Εͨ஋͔Βܾఆ͢Δ function greeting()
 {
 $str = '͜Μʹͪ͸ɺ';
 $target =

    new Robot();
 
 echo $str . $target->name;
 } TUSJOH 3PCPU
  51. ϩʔΧϧείʔϓͷม਺ͷܕਪ࿦ wJG͕͋ͬͨ৔߹ɺશͯͷՄೳੑͷ࿨ू߹ͱͳΔ w˞1IQ4UPSNͷܕਪ࿦͸ܕΛҰҙʹܾΊͣɺෳ਺ͷՄೳੑΛߟྀ͠ ͍ͯΔ function greeting()
 {
 $str = '͜Μʹͪ͸ɺ';


    $target = new Robot();
 
 if (rand(1, 0)) {
 $target = new Male();
 } else if (rand(1, 0)) {
 $target = new Female();
 }
 
 echo $str . $target->name;
 } 3PCPU ·ͨ͸ .BMF ·ͨ͸ 'FNBMF
  52. ϩʔΧϧείʔϓͷม਺ͷܕਪ࿦ wJGdFMTFͷ৔߹ɺJG෼ذͷதͷ͍ͣΕ͔͕࣮ߦ͞ΕΔ͸ͣͳͷͰɺͦΕ ΑΓ΋લͷܕ͸ແࢹ͞ΕΔ function greeting()
 {
 $str = '͜Μʹͪ͸ɺ';
 $target

    = new Robot();
 
 if (rand(1, 0)) {
 $target = new Male();
 } else {
 $target = new Female();
 }
 
 echo $str . $target->name;
 } .BMF ·ͨ͸ 'FNBMF
  53. Ҿ਺ͷܕਪ࿦ wλΠϓώϯτ͔1)1%PD͕ͳ͚Ε͹ܕਪ࿦͠ͳ͍ wݺͼग़͠ݩͷҾ਺ͷ౉͠ํ͔Βܕਪ࿦Λͨ͠Γ͸͠ͳ͍ wλΠϓώϯτͱ1)1%PD྆ํ͕͋Δ৔߹ɺͦͷ࿨ू߹ͱͳΔʢͦ΋ͦ ΋͜ͷ̎ͭʹҧ͏΋ͷΛॻ͘͜ͱࣗମ͕/(͕ͩɾɾɾʣ /**
 * @param Robot $target


    */
 function greeting(Human $target)
 {
 $target->name;
 } )VNBO ·ͨ͸ 3PCPU
  54. ໭Γ஋ͷܕਪ࿦ wશͯͷSFUVSOͷ࿨ू߹ function makeHuman()
 {
 if (rand(0, 1)) {
 return

    new Male();
 } else {
 return new Female();
 }
 
 return new Robot();
 } $human = makeHuman(); .BMF ·ͨ͸ 'FNBMF ·ͨ͸ 3PCPU ࣮ߦ࣌ʹઈରݺ͹Εͳ͍ ໭Γ஋΋ߟྀʹ͍Εͯ͠ ·͏
  55. ໭Γ஋ͷܕਪ࿦ w໭Γ஋ͷܕࢦఆ 1)1 ·ͨ͸1)1%PD͕͋Ε͹ɺͦͪΒΛ༏ઌ͢Δ w྆ํ͋Δ৔߹͸ͦͷ࿨ू߹ͱͳΔ w༏ઌॱҐɿܕࢦఆ1)1%PDSFUVSOͷ࿨ू߹ /**
 * @return Male


    */
 function makeHuman(): Human
 {
 if (rand(0, 1)) {
 return new Male();
 }
 
 return new Robot();
 } $human = makeHuman(); )VNBO ·ͨ͸ .BMF
  56. QSPQFSUZͷܕਪ࿦ wͦͷείʔϓͰͷ୅ೖͱɺίϯετϥΫλͰͷ୅ೖͷ࿨ू߹ͱͳΔ w਌DMBTTͷίϯετϥΫλͰ୅ೖ͞Ε͍ͯͯ΋ղੳର৅ͱ͢Δ class Fuga extends Hoge
 {
 public function

    greeting()
 {
 $this->human = new Female();
 $this->human->greeting();
 }
 } class Hoge
 {
 protected $human;
 
 public function __construct()
 {
 $this->human = new Male();
 }
 } .BMF ·ͨ͸ 'FNBMF
  57. QSPQFSUZͷܕਪ࿦ wղੳର৅ͷDMBTTͷίϯετϥΫλͷํ͕ɺ਌DMBTTͷίϯετϥΫλ ΑΓ༏ઌ͞ΕΔʢͪΐͬͱෆࢥٞͳڍಈɾɾɾʣ class Fuga extends Hoge
 { public function

    __construct()
 {
 $this->human = new Robot();
 parent::__construct();
 } 
 public function greeting()
 {
 $this->human = new Female();
 $this->human->greeting();
 }
 } class Hoge
 {
 protected $human;
 
 public function __construct()
 {
 $this->human = new Male();
 }
 } 3PCPU ·ͨ͸ 'FNBMF ਌DMBTTͰ.BMFͰ୅ೖ͞Ε Δ͔Βҙຯ͕ແ͍୅ೖ
  58. QSPQFSUZͷܕਪ࿦ w1)1%PD͕͋Ε͹ɺͦΕ΋࿨ू߹ʹՃΘΔ w༏ઌॱҐɿͦͷείʔϓͰͷ୅ೖʹίϯετϥΫλʹ1)1%PD class Fuga extends Hoge
 {
 public function

    greeting()
 {
 $this->human = new Female();
 $this->human->greeting();
 }
 } class Hoge
 { /**
 * @var Robot
 */
 protected $human;
 
 public function __construct()
 {
 $this->human = new Male();
 }
 } .BMF ·ͨ͸ 'FNBMF ·ͨ͸ 3PCPU
  59. άϩʔόϧείʔϓͷม਺ͷܕਪ࿦ wશͯͷϑΝΠϧͷάϩʔόϧείʔϓͷ࿨ू߹ͱͳΔ wͨͿΜ'JOE6TBHFͷର৅͔Β࿙Εͳ͍Α͏ʹɺશͯͷՄೳੑΛߟྀ ͠Α͏ͱͨ݁͠ՌͩͱࢥΘΕΔ $human = new Male(); $human =

    new Female(); $human = new Robot(); $human->greeting(); )VNBO ·ͨ͸ .BMF ·ͨ͸ 3PCPU
  60. άϩʔόϧείʔϓͷม਺ͷ'JOE6TBHF w1IQ4UPSN͸ϑΝΠϧΛ·͍ͨͩॲཧͷղੳΛͯ͘͠Εͳ͍ͬΆ͍ wઈରύεͷSFRVJSF@PODF͕ॻ͍ͯ͋ͬͯ΋ɺͦΕʹΑͬͯಡΈࠐ· ΕΔ͸ͣͷϑΝΠϧ·ͰΛؚΊͨղੳ͸͠ͳ͍ͬΆ͍ wάϩʔόϧείʔϓ͸શͯͷϑΝΠϧʹଘࡏ͢Δείʔϓ͔ͩΒɺά ϩʔόϧείʔϓͷม਺ͷܕਪ࿦͸ɺͱʹ͔͘શͯͷ࿨ू߹ͱͯ͠ѻͬ ͍ͯΔͬΆ͍ w%FDMBSBUJPO΋'JOE6TBHF΋ṖͷڍಈΛ͍ͯͯ͠ɺΑ͘෼͔Βͳ͍ ͕ɺͱʹ͔͘ػೳͯ͠ͳ͍ͱߟ͑ͯྑ͍

  61. 1IQ4UPSNͷܕਪ࿦݁ՌΛݟΔ w%PDVNFOUBUJPO ' Λԡ͢ͱΈΕΔ wͨ·ʹҧ͏಺༰͕ग़ͯ͘ΔͷͰ஫ҙ

  62. ·ͱΊ άϩʔόϧε ίʔϓͷม਺ ϩʔΧϧεί ʔϓͷม਺ GVODUJPO DMBTT QVCMJD QSPQFSUZ QSJWBUF

    QSPUFDUFE QSPQFSUZ QVCMJD NFUIPE QSJWBUF QSPUFDUFE NFUIPE %FDMBSBUJP O º ʢ˞̏ʣ ̋ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ˚
 ʢ˞̎ʣ ̋ ʢ˞̍ʣ ˚
 ʢ˞̎ʣ ̋
 ʢ˞̍ʣ 'JOE 6TBHF º ʢ˞̏ʣ ̋ ̋ ʢ˞̍ʣ ̋ ʢ˞̍ʣ ˚
 ʢ˞̎ʣ ̋
 ʢ˞̍ʣ ˚
 ʢ˞̎ʣ ̋
 ʢ˞̍ʣ ˞̍ɿಉ໊ͷGVODUJPODMBTTఆ͕ٛͳ͚Ε͹େৎ෉ ˞̎ɿݺͼग़͠ݩશͯͰܕਪ࿦͕Ͱ͖͍ͯͳ͚Ε͹࿙Ε͕ൃੜ͢Δ ˞̏ɿશάϩʔόϧείʔϓͰϢχʔΫͳ໊લͷม਺ͩͬͨΒΘΓͱ͍͚Δ
  63. ༨ஊɿઈରʹղੳͰ͖ͳ͍ύλʔϯ̍ wจࣈྻʹΑΔGVODUJPODMBTTݺͼग़͠͸ઈରʹແཧ wಉ༷ʹՄมม਺΋ແཧ $class_name = ‘Male'; 
 $male = new

    $class_name; ܕਪ࿦ෆՄ $male = new Male(); $hoge = 'male';
 $$hoge->greeting(); ܕਪ࿦ෆՄ
  64. ༨ஊɿઈରʹղੳͰ͖ͳ͍ύλʔϯ̎ wϩʔΧϧείʔϓ಺ͰͷϑΝΠϧಡΈࠐΈ wϑΝΠϧ୯ҐͰղੳ͢ΔͬΆ͍͔Βɺάϩʔόϧείʔϓͱͯ͠ѻΘ Εͯ͠·͏ function requireFuga()
 {
 $male = new

    Male();
 
 require_once __DIR__ . '/fuga.php';
 } $male->greeting(); શͯͷϑΝΠϧͷάϩʔόϧείʔϓͷ ಉ໊ͷม਺ͷ࿨ू߹ ʢάϩʔόϧείʔϓͱͯ͠ղੳ͢Δ͔Βʣ GVHBQIQ
  65. ༨ஊɿઈରʹղੳͰ͖ͳ͍ύλʔϯ̏ wϚδοΫϝιουʹΑΔະఆٛͷγϯϘϧͷݺͼग़͠ w@@TFU ະఆٛͷQSPQFSUZ΁ͷॻ͖ࠐΈ w@@HFU ະఆٛͷQSPQFSUZ΁ͷಡΈࠐΈ w@@DBMM ະఆٛͷNFUIPEͷݺͼग़͠ w@@DBMM4UBUJDະఆٛͷTUBUJDNFUIPEͷݺͼग़͠

  66. ·ͱΊ

  67. 1IQ4UPSNͷ੩తղੳ͸ඇৗʹύϫϑϧ w੩తʹܾఆ͢Δ΋ͷʢDMBTTͷߏ଄ͱ͔ʣ͸͍͍ͩͨ೺Ѳ͍ͯ͠Δ wಈతʹܾఆ͢Δ΋ͷ΋ͳΔ΂͘ղੳͯ͘͠ΕΔ wม਺ͷܕਪ࿦ wݺͼग़ؔ͠܎ wίʔυղੳΛ؆୯ʹ͢ΔखஈΛ৭ʑఏڙͯ͘͠ΕΔ wຊདྷͳΒͭΒ͍ϦϑΝΫλϦϯά΋ݡ͘΍ͬͯ͘ΕΔ

  68. 1)1ނͷݶք͸͋Δ wม਺ͷܕਪ࿦ʹ͸ݶք͸͋Δ wղੳ݁Ռ͕̍̌̌ˋ৴༻Ͱ͖ͳ͍৔߹͕͋Δʢ͍͍ͩͨܕਪ࿦ʹࣦഊ ͍ͯ͠Δ͜ͱ͕ݪҼʣ

  69. ղੳՄೳͳίʔυΛॻ͍ͯཉ͍͠ wܕਪ࿦ʹ੒ޭͤ͞Ε͹͍͍ͩͨղੳͰ͖Δ wղੳՄೳʹͳΕ͹ίʔυղੳ΍ϦϑΝΫλϦϯά͕ѹ౗తʹḿΔ w੩తʹղੳՄೳͳίʔυ͸ݎ࿚Ͱɺ͔ͭਓؒʹ΋༏͍͠ίʔυ w1)1όʔδϣϯͰදݱෆՄೳͳྖҬ΋1)1%PDΛॻ͚͹ղܾ wෳࡶԽ͍ͯ͘͠ΞϓϦέʔγϣϯʹର߅͢Δʹ͸HSFQͰ͸ෆे෼ wਓͱ*%&͕༥߹ͯ͠ίʔσΟϯάྗΛύϫʔΞοϓͤ͞Α͏ʂ