{"id":182,"date":"2024-09-16T19:10:59","date_gmt":"2024-09-16T11:10:59","guid":{"rendered":"\/?p=182"},"modified":"2024-09-16T19:11:03","modified_gmt":"2024-09-16T11:11:03","slug":"php-%e7%b1%bb","status":"publish","type":"post","link":"\/?p=182","title":{"rendered":"PHP-\u7c7b"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u7c7b\u7684\u521b\u5efa\u4e0e\u8c03\u7528<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class classname{\n    public $name = '\u5c0f\u732b';\n    public function funcname(){\n        echo $this->name.'\u5728\u559d\u6c34';\n    }\n}\n\n$cat = new classname;\n$cat->name = '\u5c0f\u72d7';\n$cat->funcname();\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u516c\u6709\u3001\u4fdd\u62a4\u3001\u79c1\u6709<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public \/\/\u516c\u6709\nprotected \/\/\u4fdd\u62a4\nprivate \/\/\u79c1\u6709<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">__construct \u51fd\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class classname{\n    public $name = '\u5c0f\u732b';\n    public function __construct()\n    {\n        $this->name = '\u5c0f\u82b1';\n    }\n    public function funcname(){\n        echo $this->name.'\u5728\u559d\u6c34';\n    }\n}\n\n$cat = new classname;\n\/\/__construct\u51fd\u6570\u4f1a\u5728new\u7c7b\u7684\u65f6\u5019\u8fd0\u884c\uff08\u53ef\u4ee5\u4f20\u53c2\uff09\n$cat->funcname();\n$cat->name = '\u5c0f\u72d7';\n$cat->funcname();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">__destruct\u51fd\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class classname{\n    public $name = '\u5c0f\u732b';\n    public function __construct()\n    {\n        $this->name = '\u5c0f\u82b1';\n    }\n    public function funcname(){\n        echo $this->name.'\u5728\u559d\u6c34';\n    }\n    public function __destruct()\n    {\n        echo '\u7c7b\u88ab\u6ce8\u9500';\n    }\n}\n$cat = new classname;\n\/\/__construct\u51fd\u6570\u4f1a\u5728new\u7c7b\u7684\u65f6\u5019\u81ea\u52a8\u8fd0\u884c\n$cat->funcname();\n$cat->name = '\u5c0f\u72d7';\n$cat->funcname();\nunset($cat);\n\/\/__destruct\u51fd\u6570\u4f1a\u5728\u7c7b\u88ab\u6ce8\u9500\u65f6\u81ea\u52a8\u8fd0\u884c<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">static \u9759\u6001\u53d8\u91cf<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class classname{\n    public $name = '\u5c0f\u732b';\n    public static $do = '\u559d\u6c34';\n    public function __construct()\n    {\n        $this->name = '\u5c0f\u82b1';\n    }\n    public function funcname(){\n        echo $this->name.'\u5728\u559d\u6c34';\n    }\n    public function take(){\n        echo $this->name.self::$do; \n    }\n    public function __destruct()\n    {\n        echo '\u7c7b\u88ab\u6ce8\u9500';\n    }\n}\n\n$cat = new classname;\n\/\/static \u4e3a\u9759\u6001\u53d8\u91cf \u8c03\u7528\u9700\u7528self\uff08\u4f7f\u7528\u9759\u6001\u53d8\u91cf\u5728\u4e0b\u4e00\u6b21new\u7c7b\u7684\u65f6\u5019\u4e0d\u4f1a\u6539\u53d8\uff09\n\/\/\u975e\u9759\u6001\u4e0d\u80fd\u5728\u9759\u6001\u51fd\u6570\u4e2d\u76f4\u63a5\u8c03\u7528\u8981\u8c03\u7528\u9700\u8981new\u4e00\u4e2a\u7c7b(new self)->name;\n$cat->take();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">const \u9759\u6001\u5e38\u91cf<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class classname{\n    public $name = '\u5c0f\u732b';\n    public static $do = '\u559d\u6c34';\n    public const ANIMAL = '\u72d7';\n    \n    public function __construct()\n    {\n        $this->name = '\u5c0f\u82b1';\n    }\n    public function funcname(){\n        echo $this->name.'\u5728\u559d\u6c34';\n    }\n    public static function take(){\n        echo self::ANIMAL.self::$do; \n    }\n    public function __destruct()\n    {\n        echo '\u7c7b\u88ab\u6ce8\u9500';\n    }\n}\n\n$cat = new classname;\n\/\/\u9759\u6001\u5e38\u91cf\u53ea\u80fd\u8bfb\u53d6\u4e0d\u80fd\u6539\u53d8\n$cat::take();\necho classname::ANIMAL;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">extends \u7c7b\u7ee7\u627f<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>\u7c7b\u7684\u521b\u5efa\u4e0e\u8c03\u7528 \u516c\u6709\u3001\u4fdd\u62a4\u3001\u79c1\u6709 __construct \u51fd\u6570 __destruct\u51fd\u6570 static \u9759\u6001\u53d8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-182","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/182"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=182"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/182\/revisions"}],"predecessor-version":[{"id":183,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/182\/revisions\/183"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}