{"id":77,"date":"2020-10-08T20:43:39","date_gmt":"2020-10-08T12:43:39","guid":{"rendered":"http:\/\/9iwd.top\/?p=77"},"modified":"2020-10-08T20:43:39","modified_gmt":"2020-10-08T12:43:39","slug":"no-20-%e5%8f%af%e5%8f%98%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"http:\/\/9iwd.top\/?p=77","title":{"rendered":"No.20 \u53ef\u53d8\/\u533f\u540d\u51fd\u6570"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\n\t\u53ef\u53d8\u51fd\u6570\n\u53ef\u53d8\u51fd\u6570\uff1a\u5f53\u524d\u6709\u4e00\u4e2a\u53d8\u91cf\u6240\u4fdd\u5b58\u5230\u503c\uff0c\u521a\u597d\u662f\u4e00\u4e2a\u51fd\u6570\u7684\u540d\u5b57\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u4f7f\u7528 \u53d8\u91cf+();\u6765\u5145\u5f53\u51fd\u6570\u540d\u4f7f\u7528\n\n$\u53d8\u91cf = 'displ';\n\nfunction display(){\n\t\/\/\u51fd\u6570\u4f53\n}\n\n\/\/\u53ef\u53d8\u51fd\u6570\u4f7f\u7528\n$\u53d8\u91cf();\n*\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5b9a\u4e49\u51fd\u6570\nfunction display(){\n\techo '\u884c\u6570\uff1a',__LINE__,'\uff1b\u51fd\u6570\u540d:',__FUNCTION__;\n}\n\n\/\/\u5b9a\u4e49\u53d8\u91cf\n$fun = 'display';\n\n\/\/\u53ef\u53d8\u51fd\u6570\n$fun();\necho '&lt;hr\/>';<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5b9a\u4e49\u7cfb\u7edf\u51fd\u6570\uff08\u5047\u8bbe\uff09\nfunction sys_function($arg1,$arg2){\n\t\/\/\u7ed9\u6307\u5b9a\u7684\u51fd\u6570(\u7b2c\u4e00\u53c2\u6570)\uff0c\u6c42\u5bf9\u5e94\u7684\u7b2c\u4e8c\u53c2\u6570\u503c\u76844\u6b21\u65b9\n\t\/\/\u4e3a\u5b9e\u9645\u7528\u6237\u8f93\u5165\u7684\u6570\u503c\u8fdb\u884c\u5904\u7406\n\t\/\/\u5c06\u4e00\u4e2a\u7528\u6237\u5b9a\u4e49\u7684\u51fd\u6570\u4f20\u5165\u7ed9\u53e6\u5916\u4e00\u4e2a\u51fd\u6570(\u51fd\u6570\u540d)\u53bb\u4f7f\u7528\u7684\u8fc7\u7a0b\uff0c\u79f0\u4e4b\u4e3a\u56de\u8c03\u8fc7\u7a0b\uff0c\u800c\u88ab\u95ef\u5165\u7684\u51fd\u6570\u79f0\u4e4b\u4e3a\u56de\u8c03\u51fd\u6570\u3002\n\t$arg2 = $arg2 + 10;\n\treturn $arg1($arg2);\n}\n\n\/\/\u5b9a\u4e49\u4e00\u4e2a\u7528\u6237\u51fd\u6570\uff1a\u6c42\u4e00\u4e2a\u6570\u76844\u6b21\u65b9\nfunction user_function($num){\n\treturn $num * $num * $num * $num;\n}\n\n\/\/\u6c4210\u76844\u6b21\u65b9\necho sys_function('user_function', 10);\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\n\t\u533f\u540d\u51fd\u6570\n\u57fa\u672c\u6982\u5ff5\n\u533f\u540d\u51fd\u6570\uff1a\u6ca1\u6709\u540d\u5b57\u7684\u51fd\u6570\n\n\u57fa\u672c\u8bed\u6cd5\uff1a\n\u53d8\u91cf\u540d = function(){\n\t\/\/\u51fd\u6570\u4f53\n};\n*\/\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/\/\u5b9a\u4e49\u57fa\u672c\u533f\u540d\u51fd\u6570\n$niming = function(){\n\t\/\/\u51fd\u6570\u4f53\n\techo 'hell world';\n};\n\n\/\/\u8c03\u7528\u533f\u540d\u51fd\u6570\n$niming();\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\n\u53d8\u91cf\u4fdd\u5b58\u533f\u540d\u51fd\u6570\uff0c\u672c\u8d28\u5f97\u5230\u7684\u662f\u4e00\u4e2a\u5bf9\u8c61(cosure)\n\n\u95ed\u5305\uff1aClosure\uff0c\u4e00\u6b21\u6765\u6e90\u4e8e\u4e00\u4e0b\u4e24\u8005\u7684\u7ed3\u5408\uff1a\n - \u8981\u6267\u884c\u7684\u4ee3\u7801\u5757\uff1a\u7531\u4e8e\u81ea\u7531\u53d8\u91cf\u88ab\u5305\u542b\u5728\u4ee3\u7801\u5757\u4e2d\uff0c\u8fd9\u5199\u81ea\u7531\u53d8\u91cf\u4e00\u7ea7\u5b83\u4eec\u7684\u5bf9\u8c61\u6ca1\u6709\u88ab\u91ca\u653e\n - \u4f5c\u7528\u57df\uff1a\u81ea\u7531\u53d8\u91cf\u63d0\u4f9b\u7ed1\u5b9a\u7684\u8ba1\u7b97\u673a\u73af\u5883\n\n\u7b80\u5355\u7406\u89e3\uff1a\n\u51fd\u6570\u5185\u90e8\u6709\u4e00\u4e9b\u5c40\u90e8\u53d8\u91cf(\u8981\u6267\u884c\u7684\u4ee3\u7801\u5757)\u5728\u51fd\u6570\u6267\u884c\u4e4b\u540e\u6ca1\u6709\u88ab\u91ca\u653e\uff0c\u662f\u56e0\u4e3a\u5728\u51fd\u6570\u5185\u90e8\u8fd8\u6709\u5bf9\u5e94\u7684\u51fd\u6570\u5728\u5f15\u7528(\u533f\u540d\u7684\u5185\u90e8\u51fd\u6570:\u533f\u540d\u51fd\u6570)\n\n*\/\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u95ed\u5305\u51fd\u6570\nfunction bibao(){\n\t\/\/\u51fd\u6570\u4f53\n\t$name = '\u884c\u6570\uff1a'.__LINE__;\n\t\/\/\u5b9a\u4e49\u533f\u540d\u51fd\u6570\n\t$niming = function() use($name){\t\/\/use()\u5c31\u662f\u5c06\u5916\u90e8\u53d8\u91cf(\u5c40\u90e8)\u4fdd\u7559\u7ed9\u5185\u90e8\u4f7f\u7528\n\t\t\/\/\u533f\u540d\u51fd\u6570 \u51fd\u6570\u4f53\n\t\t\/\/echo '\u51fd\u6570\u540d:',__FUNCTION__;\n\t\techo $name;\n\t\t\n\t};\t\/\/\u4f7f\u7528\u533f\u540d\u51fd\u6570\u9700\u8981\u5728}\u540e\u9762\u52a0\u4e0a;\u5206\u53f7\n\t\n\t\/\/\u8c03\u7528\u51fd\u6570\n\t$niming();\n\treturn $niming; \t\/\/\u8fd4\u56de\u7ed9\u5916\u90e8\u4f7f\u7528\n}\n\n\/\/\u8c03\u7528\u51fd\u6570\n$fanhui = bibao();\necho '&lt;hr\/>';\n\/*\n\u8bc1\u660e\uff1a\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u518d\u51fd\u6570\u4f7f\u7528\u5b8c\u4e4b\u540e\u6ca1\u6709\u88ab\u91ca\u653e\uff1f\n1\u3001\u4f7f\u7528\u5185\u90e8\u533f\u540d\u51fd\u6570\uff1b\n2\u3001\u533f\u540d\u51fd\u6570\u4f7f\u7528\u53e5\u53d8\u91cf\uff1ause\uff1b\n3\u3001\u533f\u540d\u51fd\u6570\u88ab\u8fd4\u56de\u7ed9\u5916\u90e8\u4f7f\u7528\uff1b\n*\/\n$fanhui();\t\t\/\/\u56e0\u4e3a\u4e0a\u9762\u8fd4\u56de\u533f\u540d\u51fd\u6570\u5230 $fanhui \u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u65b0\u53d8\u91cf\u8c03\u7528\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/posts\/77"}],"collection":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":0,"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"wp:attachment":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}