{"id":18,"date":"2025-05-11T00:00:00","date_gmt":"2025-05-10T15:00:00","guid":{"rendered":"https:\/\/pusyuuwanko.com\/wordpress\/?p=18"},"modified":"2026-10-09T20:17:41","modified_gmt":"2026-10-09T11:17:41","slug":"php%e3%81%a7%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3%ef%bc%88%e7%84%a1%e5%90%8d%e9%96%a2%e6%95%b0%ef%bc%89%e3%82%92%e6%89%b1%e3%81%86%e9%9a%9b%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9","status":"publish","type":"post","link":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/2025\/05\/11\/php%e3%81%a7%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3%ef%bc%88%e7%84%a1%e5%90%8d%e9%96%a2%e6%95%b0%ef%bc%89%e3%82%92%e6%89%b1%e3%81%86%e9%9a%9b%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9\/","title":{"rendered":"PHP\u3067\u30af\u30ed\u30fc\u30b8\u30e3\uff08\u7121\u540d\u95a2\u6570\uff09\u3092\u6271\u3046\u969b\u306e\u6ce8\u610f\u70b9"},"content":{"rendered":"<h2>PHP\u3067\u30af\u30ed\u30fc\u30b8\u30e3\uff08\u7121\u540d\u95a2\u6570\uff09\u3092\u6271\u3046\u969b\u306e\u6ce8\u610f\u70b9<\/h2>\n<p>PHP\u3067\u306f\u3001\u30af\u30ed\u30fc\u30b8\u30e3\uff08Closure\uff09\u306f\u7121\u540d\u95a2\u6570\u3068\u3057\u3066\u8a18\u8ff0\u3055\u308c\u3001\u5909\u6570\u3092\u5185\u90e8\u306b\u53d6\u308a\u8fbc\u3093\u3067\u95a2\u6570\u5185\u3067\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u67d4\u8edf\u306a\u6a5f\u80fd\u3067\u3042\u308b\u4e00\u65b9\u3001\u3044\u304f\u3064\u304b\u306e\u5236\u7d04\u3084\u6ce8\u610f\u70b9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u2705 \u57fa\u672c\u69cb\u6587<\/h3>\n<pre><code>$greet = function($name) {\n    return \"Hello, $name!\";\n};\n\necho $greet(\"World\"); \/\/ Hello, World!<\/code><\/pre>\n<h3>\ud83d\udd04 \u5916\u90e8\u5909\u6570\u3092\u4f7f\u3044\u305f\u3044\u3068\u304d\u306f use \u3092\u4f7f\u3046<\/h3>\n<pre><code>$prefix = \"Hello\";\n\n$greet = function($name) use ($prefix) {\n    return \"$prefix, $name!\";\n};<\/code><\/pre>\n<p>use \u306f \u7121\u540d\u95a2\u6570\u5b9a\u7fa9\u306e\u6642\u3060\u3051\u4f7f\u3048\u308b\u69cb\u6587\u3067\u3059\u3002<\/p>\n<p>use ($var) \u3067 \u5916\u90e8\u5909\u6570\u306e\u30b9\u30ca\u30c3\u30d7\u30b7\u30e7\u30c3\u30c8\uff08\u5024\uff09\u3092\u95a2\u6570\u306b\u9589\u3058\u8fbc\u3081\u308b\u3002<\/p>\n<p>\u5f15\u7528\u6e21\u3057\u306b\u3057\u305f\u3044\u3068\u304d\u306f use (&amp;$var)\u3002<\/p>\n<h3>\u274c \u901a\u5e38\u306e\u95a2\u6570\u3067\u306f use \u306f\u4f7f\u3048\u306a\u3044<\/h3>\n<pre><code>\/\/ NG: \u69cb\u6587\u30a8\u30e9\u30fc\u306b\u306a\u308b\nfunction greet($name) use ($prefix) {\n    return \"$prefix, $name!\";\n}<\/code><\/pre>\n<p>\u901a\u5e38\u306e function \u5b9a\u7fa9\u3067\u306f use \u306f\u4f7f\u3048\u307e\u305b\u3093\u3002\u7121\u540d\u95a2\u6570\u306e\u307f\u304c\u5bfe\u8c61\u3067\u3059\u3002<\/p>\n<h3>\u26a0\ufe0f \u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3092\u4f7f\u3046\u5834\u5408\u306e\u6ce8\u610f\u70b9<\/h3>\n<pre><code>function someFunc() {\n    global $shared;\n    echo $shared();\n}\n\n$shared = function() {\n    return \"called\";\n};\n\nsomeFunc(); \/\/ \u30a8\u30e9\u30fc\uff01<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u3001someFunc() \u304c $shared \u3092\u53c2\u7167\u3059\u308b\u524d\u306b \u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7\u3067\u521d\u671f\u5316\u3055\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>global \u3067\u53c2\u7167\u3059\u308b\u95a2\u6570\u5909\u6570\u306f\u3001\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u524d\u306b \u5b9a\u7fa9\u304c\u5b8c\u4e86\u3057\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u2705 \u30b0\u30ed\u30fc\u30d0\u30eb\u95a2\u6570\u3068\u3057\u3066\u660e\u793a\u7684\u306b\u5b9a\u7fa9\u3059\u308b\u65b9\u304c\u5b89\u5168<\/h3>\n<p>\u30af\u30ed\u30fc\u30b8\u30e3\u3068\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u3088\u308a\u3001\u518d\u5229\u7528\u304c\u591a\u3044\u95a2\u6570\u306f\u901a\u5e38\u306e\u95a2\u6570\u3068\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u65b9\u304c\u5b89\u5168\u304b\u3064\u660e\u77ad\u3067\u3059\u3002<\/p>\n<pre><code>function templatePostContents($post) {\n    \/\/ \u4f55\u304b\u306e\u51e6\u7406\n}<\/code><\/pre>\n<h3>\u2705 \u30af\u30ed\u30fc\u30b8\u30e3\u306f\u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7\u306b\u4f9d\u5b58\u3059\u308b<\/h3>\n<p>\u5b9a\u7fa9\u3057\u305f\u30b9\u30b3\u30fc\u30d7\u306e\u5909\u6570\u3057\u304b\u4f7f\u3048\u306a\u3044\uff08\u305f\u3060\u3057 use \u3067\u6301\u3061\u8fbc\u307f\u53ef\u80fd\uff09<\/p>\n<p>\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3068\u3057\u3066\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f global \u3092\u4f7f\u3046\u304b\u3001\u30af\u30ed\u30fc\u30b8\u30e3\u5916\u3067\u6e96\u5099\u3057\u3066\u304a\u304f\u3053\u3068<\/p>\n<h3>\ud83e\udde0 \u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74<\/h3>\n<p>\u672a\u5b9a\u7fa9\u306e\u95a2\u6570\u547c\u3073\u51fa\u3057\uff1a\u30af\u30ed\u30fc\u30b8\u30e3\u3092\u5b9a\u7fa9\u3059\u308b\u524d\u306b\u4f7f\u304a\u3046\u3068\u3057\u3066 undefined function \u30a8\u30e9\u30fc<\/p>\n<p>use \u306e\u66f8\u304d\u5fd8\u308c\uff1a\u5916\u90e8\u5909\u6570\u3092\u4f7f\u3046\u3064\u3082\u308a\u304c use \u3057\u5fd8\u308c\u3066 undefined variable<\/p>\n<p>\u7121\u540d\u95a2\u6570\u3092\u5024\u3068\u3057\u3066\u6301\u3063\u3066\u3044\u308b\u5909\u6570\u3092 () \u3067\u547c\u307c\u3046\u3068\u3057\u3066 null \u547c\u3073\u51fa\u3057\u30a8\u30e9\u30fc<\/p>\n<h3>\ud83d\udccc \u307e\u3068\u3081<\/h3>\n<ol>\n<li>use  \u30af\u30ed\u30fc\u30b8\u30e3\u5185\u306b\u5916\u90e8\u5909\u6570\u3092\u6301\u3061\u8fbc\u3080\u305f\u3081\u306b\u4f7f\u3046<\/li>\n<li>\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570  \u547c\u3073\u51fa\u3057\u524d\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308b<\/li>\n<li>\u901a\u5e38\u95a2\u6570\u3068\u306e\u9055\u3044 use \u306f\u30af\u30ed\u30fc\u30b8\u30e3\u5c02\u7528\u3001\u901a\u5e38\u95a2\u6570\u3067\u306f\u4f7f\u3048\u306a\u3044<\/li>\n<li>\u30b9\u30b3\u30fc\u30d7 \u30af\u30ed\u30fc\u30b8\u30e3\u306f\u5b9a\u7fa9\u6642\u30b9\u30b3\u30fc\u30d7\u306b\u4f9d\u5b58\u3057\u3001\u5916\u90e8\u5909\u6570\u3092\u4f7f\u3046\u306b\u306f\u660e\u793a\u304c\u5fc5\u8981<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u305d\u3082\u305d\u3082\u30af\u30ed\u30fc\u30b8\u30e3\u3092\u77e5\u3063\u305f\u306e\u304c\u6700\u8fd1\u3067\u3001\u66f8\u304d\u65b9\u306f\u77e5\u3063\u3066\u305f\u3093\u3067\u3059\u3051\u3069\u306d\u3002\u3002\u3002\u305d\u3093\u306a\u540d\u524d\u3060\u3063\u305f\u3068\u306f\u306d\u3001\u307e\u3041\u305d\u308c\u306f\u3055\u3066\u304a\u304d\u3001PHP\u3067\u66f8\u304f\u969b\u306fJS\u3068\u304b\u306a\u308a\u7570\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u305d\u306e\u6ce8\u610f\u70b9\u3092\u307e\u3068\u3081\u307e\u3057\u305f\uff5e<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"https:\/\/p-blog.pusyuuwanko.com\/index.php\/2025\/05\/11\/php%e3%81%a7%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3%ef%bc%88%e7%84%a1%e5%90%8d%e9%96%a2%e6%95%b0%ef%bc%89%e3%82%92%e6%89%b1%e3%81%86%e9%9a%9b%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9\/\">Continue reading<i class=\"crycon-right-dir\"><\/i><\/a><\/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":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-isami-service"],"_links":{"self":[{"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":1,"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":19,"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/posts\/18\/revisions\/19"}],"wp:attachment":[{"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-blog.pusyuuwanko.com\/index.php\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}