{"id":1622,"date":"2022-01-29T10:36:54","date_gmt":"2022-01-29T02:36:54","guid":{"rendered":"https:\/\/www.siediyer.cn\/?p=1622"},"modified":"2022-01-29T10:36:54","modified_gmt":"2022-01-29T02:36:54","slug":"php%e5%9b%9e%e8%b0%83%e5%87%bd%e6%95%b0%e7%ae%80%e5%8d%95%e7%94%a8%e6%b3%95%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=1622","title":{"rendered":"PHP\u56de\u8c03\u51fd\u6570\u7b80\u5355\u7528\u6cd5\u793a\u4f8b"},"content":{"rendered":"<p>\u672c\u6587\u5b9e\u4f8b\u8bb2\u8ff0\u4e86PHP\u56de\u8c03\u51fd\u6570\u7b80\u5355\u7528\u6cd5\u3002\u5206\u4eab\u7ed9\u5927\u5bb6\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<p>php\u4e2d\u63d0\u4f9b\u4e86\u4e24\u4e2a\u5185\u7f6e\u7684\u56de\u8c03\u51fd\u6570<code>call_user_func()<\/code>\u3001<code>call_user_func_array()<\/code>\u3002<\/p>\n<p><strong>\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u533a\u522b\u662f\uff1a<\/strong><\/p>\n<p>call_user_func_array(callable $callback,array $param_arr)\u662f\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u63a5\u53d7\u56de\u8c03\u51fd\u6570\u548c\u53c2\u6570\u7684\u3002<\/p>\n<p>call_user_func($callback, \u53c2\u65701, \u53c2\u65702)\u53c2\u6570\u7684\u4e2a\u6570\u662f\u6839\u636e\u56de\u8c03\u51fd\u6570\u6765\u51b3\u5b9a\u7684\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u56de\u8c03\u51fd\u6570\u4f7f\u7528\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/\u666e\u901a\u51fd\u6570\r\nfunction f1($param1,$param2)\r\n{\r\n echo '\u51fd\u6570'.__FUNCTION__.'\u88ab\u6267\u884c,\u4f20\u5165\u7684\u53c2\u6570\u662f:'.$param1.' '.$param2;\r\n echo \"&lt;br\/&gt;\";\r\n}\r\n\/\/\u901a\u8fc7call_user_func\u8c03\u7528\u51fd\u6570f1\r\ncall_user_func('f1','han','wen');\r\n\/\/\u901a\u8fc7call_user_func_array\u8c03\u7528\u51fd\u6570\r\ncall_user_func_array('f1',array('han','wen'));\r\n\r\n<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\u51fd\u6570f1\u88ab\u6267\u884c,\u4f20\u5165\u7684\u53c2\u6570\u662f:han wen\r\n\u51fd\u6570f1\u88ab\u6267\u884c,\u4f20\u5165\u7684\u53c2\u6570\u662f:han wen<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class A{\r\n public $name;\r\n function show($param)\r\n {\r\n  echo '\u4f20\u5165\u53c2\u6570\u662f:'.$param.\"&lt;br\/&gt;\";\r\n  echo 'my name is:'.$this-&gt;name;\r\n  echo \"&lt;br\/&gt;\";\r\n }\r\n function show1($param1,$param2)\r\n {\r\n  echo __METHOD__.'\u65b9\u6cd5\u88ab\u6267\u884c,\u4f20\u5165\u53c2\u6570\u662f:'.$param1.' '.$param2.\"&lt;br\/&gt;\";\r\n }\r\n public static function show2($param1,$param2)\r\n {\r\n  echo __METHOD__.'\u65b9\u6cd5\u88ab\u6267\u884c,\u4f20\u5165\u53c2\u6570\u662f:'.$param1.' '.$param2.\"&lt;br\/&gt;\";\r\n }\r\n}\r\n\/\/\u8c03\u7528\u7c7b\u4e2d\u975e\u9759\u6001\u6210\u5458\u51fd\u6570\uff0c\u8be5\u6210\u5458\u51fd\u6570\u4e2d\u6709$this\u8c03\u7528\u4e86\u5bf9\u8c61\u4e2d\u7684\u6210\u5458\r\n$a = new A;\r\n$a-&gt;name = 'wen';\r\ncall_user_func_array(array($a,'show',),array('han!'));\r\n\/\/\u8c03\u7528\u7c7b\u4e2d\u975e\u9759\u6001\u6210\u5458\u51fd\u6570\uff0c\u6ca1\u6709\u5bf9\u8c61\u88ab\u521b\u5efa\uff0c\u8be5\u6210\u5458\u51fd\u6570\u4e2d\u4e0d\u80fd\u6709$this\r\ncall_user_func_array(array('A','show1',),array('han!','wen'));\r\n\/\/\u8c03\u7528\u7c7b\u4e2d\u9759\u6001\u6210\u5458\u51fd\u6570\r\ncall_user_func_array(array('A','show2'),array('param1','param2'));\r\n\r\n<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\u4f20\u5165\u53c2\u6570\u662f:han!\r\nmy name is:wen\r\nA::show1\u65b9\u6cd5\u88ab\u6267\u884c,\u4f20\u5165\u53c2\u6570\u662f:han! wen\r\nA::show2\u65b9\u6cd5\u88ab\u6267\u884c,\u4f20\u5165\u53c2\u6570\u662f:param1 param2<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5b9e\u4f8b\u8bb2\u8ff0\u4e86PHP\u56de\u8c03\u51fd\u6570\u7b80\u5355\u7528\u6cd5\u3002\u5206\u4eab\u7ed9\u5927\u5bb6\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5982\u4e0b\uff1a php\u4e2d\u63d0\u4f9b\u4e86\u4e24\u4e2a\u5185\u7f6e\u7684\u56de\u8c03\u51fd\u6570cal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[120,121],"class_list":["post-1622","post","type-post","status-publish","format-standard","hentry","category-php","tag-call_user_func","tag-call_user_func_array"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1622"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1622\/revisions"}],"predecessor-version":[{"id":1623,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1622\/revisions\/1623"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}