{"id":25660,"date":"2024-11-13T23:02:36","date_gmt":"2024-11-13T14:02:36","guid":{"rendered":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25660"},"modified":"2024-11-13T23:02:38","modified_gmt":"2024-11-13T14:02:38","slug":"php-%e6%8a%bd%e8%b1%a1%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89","status":"publish","type":"post","link":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25660","title":{"rendered":"PHP \u62bd\u8c61\u30e1\u30bd\u30c3\u30c9"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nabstract class Score\n{\n    private $subject;\n    protected $points;\n\n    public function __construct($subject, $points)\n    {\n        $this-&gt;subject = $subject;\n        $this-&gt;points = $points;\n    }\n\n    abstract protected function getResult();\n\n    public function getInfo()\n    {\n        return &quot;{$this-&gt;subject}, {$this-&gt;points}, {$this-&gt;getResult()}&quot;;\n    }\n}\n\nclass MathScore extends Score\n{\n    public function __construct($points)\n    {\n        parent::__construct(&quot;Math&quot;, $points);\n    }\n\n    \/\/ protected function getResult()\n    \/\/ {\n    \/\/     echo &quot;MathScore method&quot; . PHP_EOL;\n    \/\/     return $this-&gt;points &gt;= 50 ? &quot;Pass&quot; : &quot;Fail&quot;;\n    \/\/ }\n}\n\nclass EnglishScore extends Score\n{\n    public function __construct($points)\n    {\n        parent::__construct(&quot;English&quot;, $points);\n    }\n\n    protected function getResult()\n    {\n        echo &quot;EnglishScore method&quot; . PHP_EOL;\n        return $this-&gt;points &gt;= 95 ? &quot;Pass&quot; : &quot;Fail&quot;;\n    }\n}\n\nclass User\n{\n    private $name;\n    private $score;\n\n    public function __construct($name, $score)\n    {\n        $this-&gt;name = $name;\n        $this-&gt;score = $score;\n    }\n\n    public function getInfo()\n    {\n        return &quot;{$this-&gt;name}, {$this-&gt;score-&gt;getInfo()}&quot;;\n    }\n}\n\n$user1 = new User(&quot;Taro&quot;, new MathScore(70));\n$user2 = new User(&quot;Jiro&quot;, new EnglishScore(90));\n\necho $user1-&gt;getInfo() . PHP_EOL;\necho $user2-&gt;getInfo() . PHP_EOL;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[50],"tags":[38,3],"class_list":["post-25660","post","type-post","status-publish","format-standard","hentry","category-php","tag-php","tag-programming"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25660"}],"version-history":[{"count":1,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25660\/revisions"}],"predecessor-version":[{"id":25661,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25660\/revisions\/25661"}],"wp:attachment":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25660"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}