{"id":47036,"date":"2024-12-02T16:26:01","date_gmt":"2024-12-02T08:26:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47036\/"},"modified":"2024-12-02T16:26:01","modified_gmt":"2024-12-02T08:26:01","slug":"%e9%80%9a%e8%bf%87-php-%e5%87%bd%e6%95%b0%e8%ae%bf%e9%97%ae-c-%e6%89%a9%e5%b1%95%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47036\/","title":{"rendered":"\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300a\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>PHP\u51fd\u6570\u53ef\u4ee5\u8bbf\u95eeC\u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784\uff0c\u65b9\u6cd5\u662f\u58f0\u660e\u4e00\u4e2aPHP\u51fd\u6570\uff0c\u4f7f\u7528\u7279\u6b8a\u7684\u8bed\u6cd5\uff1afunction function_name(int $arg1, void $arg2, array $arg3) : \\Namespace\\CStructName\uff0c\u5176\u4e2d$arg1, $arg2\u548c$arg3\u662f\u4f20\u9012\u7ed9C\u51fd\u6570\u7684\u53c2\u6570\uff0c \\Namespace\\CStructName\u662fC\u6570\u636e\u7ed3\u6784\u7684\u7c7b\u578b\u63d0\u793a\u3002\u5b9e\u6218\u6848\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u5728PHP\u51fd\u6570\u4e2d\u8bbf\u95eeC\u6269\u5c55\u4e2d\u7684MyStruct\u6570\u636e\u7ed3\u6784\uff0c\u5e76\u4ecePHP\u811a\u672c\u8c03\u7528\u8be5\u51fd\u6570\u4ee5\u83b7\u5f97\u7ed3\u6784\u6210\u5458\u7684\u503c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729861180671b963ca2af6.jpg\" class=\"aligncenter\" title=\"\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u63d2\u56fe\" alt=\"\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784<\/strong><\/p>\n<p>PHP \u6269\u5c55\u4f7f\u6211\u4eec\u80fd\u591f\u4f7f\u7528 C \u51fd\u6570\u6269\u5c55 PHP \u529f\u80fd\u3002\u5176\u4e2d\u4e00\u9879\u529f\u80fd\u662f\u80fd\u591f\u8bbf\u95ee C \u6570\u636e\u7ed3\u6784\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u58f0\u660e\u4e00\u4e2a PHP \u51fd\u6570\u5e76\u4f7f\u7528\u7279\u6b8a\u7684\u8bed\u6cd5\u6765\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<pre>function function_name(int $arg1, void $arg2, array $arg3) : \\Namespace\\CStructName<\/pre>\n<ul>\n<li><code>function_name<\/code>\uff1aPHP \u51fd\u6570\u540d\u79f0\u3002<\/li>\n<li><code>$arg1<\/code>, <code>$arg2<\/code>, <code>$arg3<\/code>\uff1a\u4f20\u9012\u7ed9 C \u51fd\u6570\u7684\u53c2\u6570\u3002<\/li>\n<li><code>: \\Namespace\\CStructName<\/code>\uff1a\u8fd4\u56de C \u6570\u636e\u7ed3\u6784\u7684\u7c7b\u578b\u63d0\u793a\u3002<\/li>\n<li><code>int<\/code>, <code>void<\/code>, <code>array<\/code>\uff1a\u53c2\u6570\u7c7b\u578b\u3002<\/li>\n<li><code>\\Namespace\\CStructName<\/code>\uff1aC \u6570\u636e\u7ed3\u6784\u7684\u547d\u540d\u7a7a\u95f4\u548c\u7c7b\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4e00\u4e2a\u540d\u4e3a <code>my_extension<\/code> \u7684 C \u6269\u5c55\uff0c\u5b83\u5305\u542b\u4ee5\u4e0b\u6570\u636e\u7ed3\u6784\uff1a<\/p>\n<pre>typedef struct {\n    int x;\n    double y;\n} MyStruct;<\/pre>\n<p>\u8981\u4ece PHP \u51fd\u6570\u8bbf\u95ee\u6b64\u6570\u636e\u7ed3\u6784\uff0c\u6211\u4eec\u53ef\u4ee5\u58f0\u660e\u4ee5\u4e0b PHP \u51fd\u6570\uff1a<\/p>\n<pre>function get_my_struct(int $x, void $y, array $z) : \\MyExtension\\MyStruct\n{\n    MyStruct my_struct;\n    my_struct.x = $x;\n    my_struct.y = $y;\n\n    return $my_struct;\n}<\/pre>\n<p>\u5728\u8fd9\u4e2a PHP \u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u58f0\u660e\u4e86\u4e00\u4e2a\u540d\u4e3a <code>get_my_struct<\/code> \u7684\u51fd\u6570\uff0c\u5b83\u63a5\u53d7\u4e09\u4e2a\u53c2\u6570\uff1a<code>$x<\/code>\uff08\u7c7b\u578b\u63d0\u793a\u4e3a <code>int<\/code>\uff09\u3001<code>$y<\/code>\uff08\u7c7b\u578b\u63d0\u793a\u4e3a <code>void<\/code>\uff09\u548c <code>$z<\/code>\uff08\u7c7b\u578b\u63d0\u793a\u4e3a <code>array<\/code>\uff09\u3002<\/p>\n<p>\u51fd\u6570\u4f53\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a <code>MyStruct<\/code> \u5b9e\u4f8b\u5e76\u5c06 <code>$x<\/code> \u548c <code>$y<\/code> \u7684\u503c\u5206\u914d\u7ed9\u5b83\u7684\u6210\u5458\u3002\u7136\u540e\uff0c\u6211\u4eec\u8fd4\u56de <code>my_struct<\/code> \u5b9e\u4f8b\u3002<\/p>\n<p><strong>\u8c03\u7528 PHP \u51fd\u6570<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u4ece PHP \u811a\u672c\u8c03\u7528 <code>get_my_struct<\/code> \u51fd\u6570\uff1a<\/p>\n<pre>$my_struct = get_my_struct(10, NULL, []);\n\necho $my_struct-&gt;x; \/\/ \u8f93\u51fa\uff1a10<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784 \u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300a\u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01 PHP\u51fd\u6570\u53ef\u4ee5\u8bbf\u95eeC\u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784\uff0c\u65b9\u6cd5\u662f\u58f0\u660e\u4e00\u4e2aPHP\u51fd\u6570\uff0c\u4f7f\u7528\u7279\u6b8a\u7684\u8bed\u6cd5\uff1afunction function_name(int $arg1, void $arg2, array $arg3) : \\Namespace\\CStructName\uff0c\u5176\u4e2d$arg1, $arg2\u548c$arg3\u662f\u4f20\u9012\u7ed9C\u51fd\u6570\u7684\u53c2\u6570\uff0c \\Namespace\\CStructName\u662fC\u6570\u636e\u7ed3\u6784\u7684\u7c7b\u578b\u63d0\u793a\u3002\u5b9e\u6218\u6848\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u5728PHP\u51fd\u6570\u4e2d\u8bbf\u95eeC\u6269\u5c55\u4e2d\u7684MyStruct\u6570\u636e\u7ed3\u6784\uff0c\u5e76\u4ecePHP\u811a\u672c\u8c03\u7528\u8be5\u51fd\u6570\u4ee5\u83b7\u5f97\u7ed3\u6784\u6210\u5458\u7684\u503c\u3002 \u901a\u8fc7 PHP \u51fd\u6570\u8bbf\u95ee C \u6269\u5c55\u4e2d\u7684\u6570\u636e\u7ed3\u6784 PHP \u6269\u5c55\u4f7f\u6211\u4eec\u80fd\u591f\u4f7f\u7528 C \u51fd\u6570\u6269\u5c55 PHP \u529f\u80fd\u3002\u5176\u4e2d\u4e00\u9879\u529f\u80fd\u662f\u80fd\u591f\u8bbf\u95ee C \u6570\u636e\u7ed3\u6784\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u58f0\u660e\u4e00\u4e2a PHP \u51fd\u6570\u5e76\u4f7f\u7528\u7279\u6b8a\u7684\u8bed\u6cd5\u6765\u5b9e\u73b0\u3002 \u8bed\u6cd5 function function_name(int $arg1, void $arg2, array $arg3) : \\Namespace\\CStructName function_name\uff1aPHP \u51fd\u6570\u540d\u79f0\u3002 $arg1, $arg2, $arg3\uff1a\u4f20\u9012\u7ed9 C \u51fd\u6570\u7684\u53c2\u6570\u3002 : \\Namespace\\CStructName\uff1a\u8fd4\u56de [&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-47036","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47036","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=47036"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47036\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}