{"id":48408,"date":"2024-12-02T17:49:15","date_gmt":"2024-12-02T09:49:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48408\/"},"modified":"2024-12-02T17:49:15","modified_gmt":"2024-12-02T09:49:15","slug":"php-7-%e4%b8%ad-php-%e5%87%bd%e6%95%b0%e5%92%8c-c-%e6%89%a9%e5%b1%95%e4%ba%a4%e4%ba%92%e7%9a%84%e6%94%b9%e8%bf%9b%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48408\/","title":{"rendered":"PHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p>PHP 7 \u6539\u8fdb\u4e86 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u65b9\u5f0f\uff0c\u4e3b\u8981\u5305\u542b\u4ee5\u4e0b\u6539\u8fdb\uff1a\u5f15\u5165\u4e86\u51fd\u6570\u6307\u9488\uff0c\u5141\u8bb8 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e2d\u51fd\u6570\u6307\u9488\u4ea4\u4e92\u3002\u65b0\u589e\u53ef\u53d8\u53c2\u6570\u652f\u6301\uff0c\u5141\u8bb8 C \u6269\u5c55\u51fd\u6570\u5177\u6709\u53ef\u53d8\u53c2\u6570\u5217\u8868\u3002\u63d0\u4f9b\u4e86\u7c7b\u578b\u63d0\u793a\u529f\u80fd\uff0c\u53ef\u68c0\u67e5 PHP \u51fd\u6570\u8c03\u7528\u53c2\u6570\u7c7b\u578b\u3002\u5141\u8bb8\u4e3a C \u6269\u5c55\u51fd\u6570\u6307\u5b9a\u8fd4\u56de\u503c\u7c7b\u578b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730025035671e164bd2131.jpg\" class=\"aligncenter\" title=\"PHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"PHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP 7 \u4e2d PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u5728 PHP 7 \u4e2d\uff0c\u5bf9 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e4b\u95f4\u7684\u4ea4\u4e92\u8fdb\u884c\u4e86\u91cd\u5927\u6539\u8fdb\u3002\u8fd9\u4e9b\u6539\u8fdb\u4f7f\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u66f4\u8f7b\u677e\u3001\u66f4\u9ad8\u6548\u5730\u5f00\u53d1\u81ea\u5df1\u7684\u6269\u5c55\u3002<\/p>\n<p><strong>\u51fd\u6570\u6307\u9488<\/strong><\/p>\n<p>PHP 7 \u5f15\u5165\u4e86\u51fd\u6570\u6307\u9488\uff0c\u5b83\u5141\u8bb8 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e2d\u7684\u51fd\u6570\u6307\u9488\u8fdb\u884c\u4ea4\u4e92\u3002\u8fd9\u901a\u8fc7 <code>zend_function<\/code> \u7ed3\u6784\u5b9e\u73b0\uff0c\u5b83\u5305\u542b\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\u548c\u6307\u5411\u51fd\u6570\u539f\u578b\u4fe1\u606f\u7684\u6307\u9488\u3002<\/p>\n<p><strong>\u4f7f\u7528\u51fd\u6570\u6307\u9488<\/strong><\/p>\n<p>\u8981\u4f7f\u7528\u51fd\u6570\u6307\u9488\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<ol>\n<li>\n<p>\u58f0\u660e\u4e00\u4e2a <code>zend_function<\/code> \u7ed3\u6784\uff1a<\/p>\n<pre>zend_function my_function;<\/pre>\n<\/li>\n<li>\n<p>\u5c06\u51fd\u6570\u6307\u9488\u590d\u5236\u5230\u7ed3\u6784\u4e2d\uff1a<\/p>\n<pre>my_function.handler = &amp;my_function_handler;<\/pre>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u51fd\u6570\u539f\u578b\uff1a<\/p>\n<pre>my_function.type = ZEND_INTERNAL_FUNCTION;\nmy_function.module =  &amp;my_extension_module;<\/pre>\n<\/li>\n<\/ol>\n<p><strong>\u6848\u4f8b<\/strong><\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528\u51fd\u6570\u6307\u9488\u7684\u7b80\u5355\u4f8b\u5b50\uff1a<\/p>\n<p><strong>foo.c<\/strong><\/p>\n<pre>#include \"php.h\"\n\nstatic PHP_FUNCTION(my_func)\n{\n    \/\/ ...\n}\n\nzend_function_entry my_functions[] = {\n    PHP_FE(my_func, NULL),\n    {NULL, NULL, NULL}\n};\n\nzend_module_entry my_extension_module = {\n    STANDARD_MODULE_HEADER,\n    NULL,\n    NULL,\n    \"My extension\",\n    my_functions,\n    NULL,\n    NULL,\n    NULL,\n    NULL,\n    NULL,\n    NULL,\n    0,\n    0,\n    \"1.0\",\n};\n\nZEND_GET_MODULE(my_extension_module)<\/pre>\n<p><strong>foo.php<\/strong><\/p>\n<pre>&lt;?php\n$my_function = \\DateTime::class . '::createFromFormat';\n$function_pointer = $my_function-&gt;getClosure()-&gt;bindTo();\n$new_object = $function_pointer('d\/m\/Y', '1\/1\/2020');<\/pre>\n<p><strong>\u5176\u4ed6\u6539\u8fdb<\/strong><\/p>\n<p>\u9664\u4e86\u51fd\u6570\u6307\u9488\u5916\uff0cPHP 7 \u8fd8\u5f15\u5165\u4e86\u4e00\u4e9b\u5176\u4ed6\u6539\u8fdb\uff0c\u4ee5\u589e\u5f3a PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u7684\u4ea4\u4e92\uff1a<\/p>\n<ul>\n<li><strong>\u53ef\u53d8\u53c2\u6570\u652f\u6301\uff1a<\/strong>PHP 7 \u5141\u8bb8 C \u6269\u5c55\u4e2d\u7684\u51fd\u6570\u5177\u6709\u53ef\u53d8\u53c2\u6570\u5217\u8868\u3002<\/li>\n<li><strong>\u7c7b\u578b\u63d0\u793a\uff1a<\/strong>\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u63d0\u793a\u6765\u68c0\u67e5 PHP \u51fd\u6570\u8c03\u7528\u4e2d\u4f20\u9012\u7684\u53c2\u6570\u7c7b\u578b\u3002<\/li>\n<li><strong>\u8fd4\u56de\u503c\u7c7b\u578b\uff1a<\/strong>\u53ef\u4ee5\u4e3a C \u6269\u5c55\u4e2d\u7684\u51fd\u6570\u6307\u5b9a\u8fd4\u56de\u503c\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>PHP 7 \u4e2d PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e4b\u95f4\u7684\u4ea4\u4e92\u7684\u8fd9\u4e9b\u6539\u8fdb\u4f7f\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u66f4\u8f7b\u677e\u3001\u66f4\u9ad8\u6548\u5730\u5f00\u53d1\u6269\u5c55\u3002\u8fd9\u4e9b\u6539\u8fdb\u4fc3\u8fdb\u4e86\u66f4\u9c81\u68d2\u3001\u66f4\u53ef\u7ef4\u62a4\u7684\u6269\u5c55\u7684\u5f00\u53d1\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8ephp,C\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f \u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9\u6587\u7ae0\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587\u300aPHP 7 \u4e2d PHP \u51fd\u6570\u548c C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb\u662f\u4ec0\u4e48\uff1f\u300b\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~ PHP 7 \u6539\u8fdb\u4e86 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u65b9\u5f0f\uff0c\u4e3b\u8981\u5305\u542b\u4ee5\u4e0b\u6539\u8fdb\uff1a\u5f15\u5165\u4e86\u51fd\u6570\u6307\u9488\uff0c\u5141\u8bb8 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e2d\u51fd\u6570\u6307\u9488\u4ea4\u4e92\u3002\u65b0\u589e\u53ef\u53d8\u53c2\u6570\u652f\u6301\uff0c\u5141\u8bb8 C \u6269\u5c55\u51fd\u6570\u5177\u6709\u53ef\u53d8\u53c2\u6570\u5217\u8868\u3002\u63d0\u4f9b\u4e86\u7c7b\u578b\u63d0\u793a\u529f\u80fd\uff0c\u53ef\u68c0\u67e5 PHP \u51fd\u6570\u8c03\u7528\u53c2\u6570\u7c7b\u578b\u3002\u5141\u8bb8\u4e3a C \u6269\u5c55\u51fd\u6570\u6307\u5b9a\u8fd4\u56de\u503c\u7c7b\u578b\u3002 PHP 7 \u4e2d PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4ea4\u4e92\u7684\u6539\u8fdb \u7b80\u4ecb \u5728 PHP 7 \u4e2d\uff0c\u5bf9 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e4b\u95f4\u7684\u4ea4\u4e92\u8fdb\u884c\u4e86\u91cd\u5927\u6539\u8fdb\u3002\u8fd9\u4e9b\u6539\u8fdb\u4f7f\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u66f4\u8f7b\u677e\u3001\u66f4\u9ad8\u6548\u5730\u5f00\u53d1\u81ea\u5df1\u7684\u6269\u5c55\u3002 \u51fd\u6570\u6307\u9488 PHP 7 \u5f15\u5165\u4e86\u51fd\u6570\u6307\u9488\uff0c\u5b83\u5141\u8bb8 PHP \u51fd\u6570\u4e0e C \u6269\u5c55\u4e2d\u7684\u51fd\u6570\u6307\u9488\u8fdb\u884c\u4ea4\u4e92\u3002\u8fd9\u901a\u8fc7 [&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-48408","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48408","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=48408"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48408\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}