{"id":3944,"date":"2020-07-17T11:35:30","date_gmt":"2020-07-17T03:35:30","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=3944"},"modified":"2020-07-17T11:35:30","modified_gmt":"2020-07-17T03:35:30","slug":"%e9%9d%9c%e6%85%8b%e5%b1%ac%e6%80%a7%e8%88%87%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=3944","title":{"rendered":"[ PHP ] \u2013 OOP 12 \u7269\u4ef6\u5c0e\u5411\u4e2d \u975c\u614b\u5c6c\u6027\u8207\u65b9\u6cd5 \u7684\u4f7f\u7528\u53ca\u7279\u6027"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u518d\u4f86\u4ecb\u7d39 \u7269\u4ef6\u5c0e\u5411\u4e2d \u975c\u614b\u5c6c\u6027\u8207\u65b9\u6cd5\u7684\u4f7f\u7528\u53ca\u7279\u6027\uff0c\u5b83\u662f\u5c6c\u65bc\u6574\u500b\u985e\u800c\u975e\u5be6\u9ad4\u6240\u4ee5\u4e0d\u7528\u751f\u6210\u5c31\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\nclass computer {\n\tpublic static $num = 0;\n\tpublic static function add (){\n\t\treturn self::$num+=1;\n\t}\n}\n\/\/\necho computer::$num.'&lt;br>';\/\/\u521d\u59cb\u503c\necho computer::add().'&lt;br>';\/\/\u7b2c\u4e00\u6b21\u547c\u53eb \u986f\u793a1\necho computer::add().'&lt;br>';\/\/\u7b2c\u4e8c\u6b21\u547c\u53eb \u986f\u793a2\necho computer::add().'&lt;br>';\/\/\u7b2c\u4e09\u6b21\u547c\u53eb \u986f\u793a3\nclass b extends computer {\n\tpublic static function add (){ \/\/\u8986\u5beb\u7236\u65b9\u6cd5\n\t\treturn self::$num+=2;\/\/\u6539\u52a02\n\t}\n}\necho b::$num.'&lt;br>';\/\/\u503c\u8b8a \u5df2\u7d93\u8b8a3\necho b::add().'&lt;br>';\/\/\u5b50\u985e\u5225\u5df2\u8986\u5beb\u7236\u7684\u65b9\u6cd5 \u6240\u4ee5\u662f\u52a02 \u4e0d\u662f\u52a01 \u986f\u793a5\n\/\/\u975c\u614b\u5c6c\u6027\u8207\u65b9\u6cd5 \u4f7f\u7528\u6642\u4e0d\u7528\u751f\u6210\u7269\u4ef6\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 \u985e\u5225\u540d\u7a31::\u975c\u614b\u5c6c\u6027 \u985e\u5225\u540d\u7a31\u975c\u614b\u65b9\u6cd5()\n\/\/\u975c\u614b\u5c6c\u6027\u8207\u65b9\u6cd5 \u5728\u985e\u5225\u4e2d\u9700\u4f7f\u7528 self or static \u4e0d\u53ef\u4f7f\u7528 this\n\/\/\u986f\u793a\u7d50\u679c\n\/*\n1\n2\n3\n3\n5\n*\/<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u518d\u4f86\u4ecb\u7d39 \u7269\u4ef6\u5c0e\u5411\u4e2d \u975c\u614b\u5c6c\u6027\u8207\u65b9\u6cd5\u7684\u4f7f\u7528\u53ca\u7279\u6027\uff0c\u5b83\u662f\u5c6c\u65bc\u6574\u500b\u985e\u800c\u975e\u5be6\u9ad4\u6240\u4ee5\u4e0d\u7528\u751f\u6210\u5c31\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":2201,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,36],"tags":[429,448,505,531,1273,1274],"class_list":["post-3944","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oop","category-php","tag-oop","tag-php","tag-self","tag-static","tag-1273","tag-1274","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3944"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3944\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/2201"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}