{"id":22797,"date":"2024-11-21T13:53:23","date_gmt":"2024-11-21T05:53:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22797\/"},"modified":"2024-11-21T13:53:23","modified_gmt":"2024-11-21T05:53:23","slug":"laravel-%e5%a6%82%e4%bd%95-new-php-%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22797\/","title":{"rendered":"laravel \u5982\u4f55 new php \u7c7b"},"content":{"rendered":"<p>laravel \u662f\u4e00\u4e2a\u5f00\u6e90\u7684 php web \u5e94\u7528\u6846\u67b6\uff0c\u5b83\u88ab\u5e7f\u6cdb\u8fd0\u7528\u4e8e\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u548c\u6613\u7ef4\u62a4\u7684 web \u5e94\u7528\u3002laravel \u7684\u4f18\u52bf\u5728\u4e8e\u5176\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u6613\u4e8e\u4f7f\u7528\u7684\u8bed\u6cd5\uff0c\u540c\u65f6\u4e5f\u652f\u6301\u5f88\u591a\u73b0\u4ee3\u5316\u7684\u7f16\u7a0b\u6982\u5ff5\u3002\u5728 laravel \u4e2d\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u65b0\u7684 php \u7c7b\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728 laravel \u4e2d\u521b\u5efa\u65b0\u7684 php \u7c7b\u3002<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u7c7b\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u6587\u4ef6<br \/>\u5728 Laravel \u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u7c7b\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a PHP \u6587\u4ef6\u3002\u53ef\u4ee5\u5728 app \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u6587\u4ef6\uff0c\u6bd4\u5982 app\/MyClass.php\u3002\u8fd9\u4e2a\u6587\u4ef6\u5c06\u6210\u4e3a\u4f60\u6240\u521b\u5efa\u7684\u65b0\u7c7b\u7684\u4ee3\u7801\u6587\u4ef6\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u4f60\u9700\u8981\u7f16\u5199\u7c7b\u7684\u5b9a\u4e49\u548c\u4ee3\u7801\u3002<\/li>\n<li>\u5b9a\u4e49\u4f60\u7684 PHP \u7c7b<br \/>\u4e00\u822c\u6765\u8bf4\uff0c\u5728\u4f60\u7684 PHP \u6587\u4ef6\u4e2d\uff0c\u4f60\u9700\u8981\u7f16\u5199\u4e00\u4e2a\u7c7b\u5b9a\u4e49\u3002\u4e00\u4e2a\u7c7b\u5b9a\u4e49\u7531\u4e09\u4e2a\u90e8\u5206\u7ec4\u6210\uff1a\u7c7b\u540d\u3001\u7c7b\u5c5e\u6027\u548c\u7c7b\u65b9\u6cd5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u6709\u7740\u4e00\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u7684 PHP \u7c7b\u5b9a\u4e49\u7684\u4f8b\u5b50\uff1a<\/li>\n<\/ol>\n<pre>&lt;?php class MyClass\n{\n    \/\/ \u7c7b\u5c5e\u6027\n    private $foo;\n    \n    \/\/ \u6784\u9020\u51fd\u6570\n    public function __construct($value)\n    {\n        $this-&gt;foo = $value;\n    }\n    \n    \/\/ \u7c7b\u65b9\u6cd5\n    public function doSomething()\n    {\n        echo 'Doing something with ' . $this-&amp;gt;foo . \"\n\";\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a MyClass \u7684\u7c7b\uff0c\u5b83\u6709\u4e00\u4e2a\u79c1\u6709\u5c5e\u6027 $foo\uff0c\u5b83\u6709\u4e00\u4e2a\u540d\u4e3a __construct \u7684\u6784\u9020\u51fd\u6570\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570 $value\uff0c\u5e76\u5c06\u5b83\u4fdd\u5b58\u5230 $foo \u5c5e\u6027\u4e2d\u3002\u5b83\u8fd8\u6709\u4e00\u4e2a\u540d\u4e3a doSomething \u7684\u65b9\u6cd5\uff0c\u5b83\u4f1a\u8f93\u51fa\u67d0\u4e9b\u5185\u5bb9\u3002\u4f60\u53ef\u4ee5\u5728\u8fd9\u4e2a\u7c7b\u4e2d\u5b9a\u4e49\u4efb\u610f\u6570\u91cf\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<ol>\n<li>\u5728 Laravel \u4e2d\u4f7f\u7528\u4f60\u7684 PHP \u7c7b<br \/>\u4e00\u65e6\u4f60\u521b\u5efa\u4e86\u4f60\u7684 PHP \u7c7b\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728 Laravel \u4e2d\u4f7f\u7528\u5b83\u4e86\u3002Laravel \u9ed8\u8ba4\u4f1a\u81ea\u52a8\u52a0\u8f7d\u5728 app \u76ee\u5f55\u4e0b\u7684\u7c7b\uff0c\u56e0\u6b64\uff0c\u5728\u4f60\u7684 Laravel \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 use \u5173\u952e\u5b57\u5f15\u7528\u4f60\u7684\u7c7b\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u3002<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 MyClass \u7c7b\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre>&lt;?php use AppMyClass;\n\n$myObj = new MyClass('bar');\n$myObj-&gt;doSomething();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86 use \u5173\u952e\u5b57\u6765\u5f15\u7528 MyClass \u7c7b\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a $myObj \u7684\u65b0\u5bf9\u8c61\uff0c\u4f20\u9012\u4e86\u5b57\u7b26\u4e32 &#8216;bar&#8217; \u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u3002\u6700\u540e\uff0c\u6211\u4eec\u8c03\u7528\u4e86\u5bf9\u8c61\u7684 doSomething() \u65b9\u6cd5\u6765\u8f93\u51fa\u5185\u5bb9\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5728\u5b9e\u9645\u7684 Laravel \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5728\u63a7\u5236\u5668\u6216\u670d\u52a1\u7c7b\u4e2d\u4f7f\u7528\u4f60\u7684 PHP \u7c7b\uff0c\u6216\u8005\u5728\u4f60\u7684\u89c6\u56fe\u4e2d\u6e32\u67d3\u6570\u636e\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u9700\u8981\u6839\u636e\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u9002\u914d\u4f60\u7684 PHP \u7c7b\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728 Laravel \u4e2d\u521b\u5efa\u65b0\u7684 PHP \u7c7b\u3002\u6211\u4eec\u4ece\u521b\u5efa PHP \u6587\u4ef6\u5f00\u59cb\uff0c\u7136\u540e\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5305\u542b\u5c5e\u6027\u548c\u65b9\u6cd5\u7684\u7c7b\uff0c\u6700\u540e\u6211\u4eec\u5728 Laravel \u4e2d\u5f15\u7528\u548c\u4f7f\u7528\u4e86\u8fd9\u4e2a\u65b0\u7684 PHP \u7c7b\u3002\u5f53\u7136\uff0c\u8fd9\u53ea\u662f Laravel \u63d0\u4f9b\u7684\u5f3a\u5927\u529f\u80fd\u7684\u4e00\u4e2a\u65b9\u9762\uff0c\u5982\u679c\u4f60\u60f3\u66f4\u8be6\u7ec6\u5730\u4e86\u89e3 Laravel\uff0c\u8bf7\u67e5\u9605\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662flaravel \u5982\u4f55 new php \u7c7b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>laravel \u662f\u4e00\u4e2a\u5f00\u6e90\u7684 php web \u5e94\u7528\u6846\u67b6\uff0c\u5b83\u88ab\u5e7f\u6cdb\u8fd0\u7528\u4e8e\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u548c\u6613\u7ef4\u62a4\u7684 web \u5e94\u7528\u3002laravel \u7684\u4f18\u52bf\u5728\u4e8e\u5176\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u6613\u4e8e\u4f7f\u7528\u7684\u8bed\u6cd5\uff0c\u540c\u65f6\u4e5f\u652f\u6301\u5f88\u591a\u73b0\u4ee3\u5316\u7684\u7f16\u7a0b\u6982\u5ff5\u3002\u5728 laravel \u4e2d\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u65b0\u7684 php \u7c7b\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728 laravel \u4e2d\u521b\u5efa\u65b0\u7684 php \u7c7b\u3002 \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u7c7b\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u6587\u4ef6\u5728 Laravel \u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u7c7b\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a PHP \u6587\u4ef6\u3002\u53ef\u4ee5\u5728 app \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 PHP \u6587\u4ef6\uff0c\u6bd4\u5982 app\/MyClass.php\u3002\u8fd9\u4e2a\u6587\u4ef6\u5c06\u6210\u4e3a\u4f60\u6240\u521b\u5efa\u7684\u65b0\u7c7b\u7684\u4ee3\u7801\u6587\u4ef6\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u4f60\u9700\u8981\u7f16\u5199\u7c7b\u7684\u5b9a\u4e49\u548c\u4ee3\u7801\u3002 \u5b9a\u4e49\u4f60\u7684 PHP \u7c7b\u4e00\u822c\u6765\u8bf4\uff0c\u5728\u4f60\u7684 PHP \u6587\u4ef6\u4e2d\uff0c\u4f60\u9700\u8981\u7f16\u5199\u4e00\u4e2a\u7c7b\u5b9a\u4e49\u3002\u4e00\u4e2a\u7c7b\u5b9a\u4e49\u7531\u4e09\u4e2a\u90e8\u5206\u7ec4\u6210\uff1a\u7c7b\u540d\u3001\u7c7b\u5c5e\u6027\u548c\u7c7b\u65b9\u6cd5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u6709\u7740\u4e00\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u7684 PHP \u7c7b\u5b9a\u4e49\u7684\u4f8b\u5b50\uff1a &lt;?php class MyClass { \/\/ \u7c7b\u5c5e\u6027 private $foo; \/\/ \u6784\u9020\u51fd\u6570 public function __construct($value) { $this-&gt;foo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-22797","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=22797"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22797\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}