{"id":86,"date":"2021-04-22T04:20:36","date_gmt":"2021-04-21T19:20:36","guid":{"rendered":"https:\/\/tech.for-easy-learning.com\/?p=86"},"modified":"2021-04-29T11:54:50","modified_gmt":"2021-04-29T02:54:50","slug":"%e3%80%90php%e3%80%91%e3%82%aa%e3%83%ac%e3%82%aa%e3%83%ac-backtrace-%e3%83%ad%e3%82%b0%e3%82%92%e5%87%ba%e5%8a%9b%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/tech.for-easy-learning.com\/?p=86","title":{"rendered":"\u3010PHP\u3011\u30aa\u30ec\u30aa\u30ec backtrace \u30ed\u30b0\u3092\u51fa\u529b\u3057\u3066\u547c\u51fa\u5143\u3092\u8fbf\u308b"},"content":{"rendered":"\n<p>PHP \u3067\u306f <a href=\"https:\/\/www.php.net\/manual\/ja\/function.debug-print-backtrace\" data-type=\"URL\" data-id=\"https:\/\/www.php.net\/manual\/ja\/function.debug-print-backtrace\">debug_print_backtrace()<\/a> \u3067\u30d0\u30c3\u30af\u30c8\u30ec\u30fc\u30b9\u3092\u8868\u793a\u3067\u304d\u308b\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u4f8b\u306e\u3088\u3046\u306b<strong>\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u3069\u3046\u3044\u3046\u9806\u756a\u3067\u5b9f\u884c\u3055\u308c\u305f\u304b\u3092\u30c7\u30d0\u30c3\u30b0<\/strong>\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" >#\u756a\u53f7 \u95a2\u6570\u540d(\u5f15\u6570\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8) called at [\u30d5\u30a1\u30a4\u30eb\u306e\u30d5\u30eb\u30d1\u30b9:\u884c\u6570]\n...\n\n\u4f8b\uff09\n#0  Dog-&gt;run(2) called at [\/Applications\/MAMP\/htdocs\/xxx\/main.php:28]<\/pre><\/div>\n\n\n\n<p>\u4f8b\u3048\u3070\u3053\u3093\u306a\u611f\u3058\u306e3\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u3063\u305f\u5834\u5408<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"toolbar:1 lang:php decode:true \" title=\"xxx\/dog.php\" >&lt;?php\n\nclass Dog {\n  static function bark() {\n    debug_print_backtrace();\n    echo \"bowwow\\n\";\n  }\n}\n\n?&gt;<\/pre><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"toolbar:1 lang:php decode:true \" title=\"xxx\/cat.php\" >&lt;?php\n\nclass Cat {\n  static function bark() {\n    debug_print_backtrace();\n    echo \"meowmeow\\n\";\n  }\n}\n\n?&gt;<\/pre><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"toolbar:1 lang:php decode:true \" title=\"xxx\/main.php\" >&lt;?php\nrequire_once __DIR__.'\/dog.php';\nrequire_once __DIR__.'\/cat.php';\n\nclass Main {\n  static function bark($animals) {\n    foreach ($animals as $aClass) {\n      $aClass::bark();\n    }\n  }\n\n  function dogBark() {\n    Dog::bark();\n  }\n}\n\necho \"start.\\n\";\nMain::bark(['Dog', 'Cat']);\n(new Main())-&gt;dogBark();\n\n?&gt;<\/pre><\/div>\n\n\n\n<p>\u51fa\u529b\u306f\u3053\u3046\u306a\u308b\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" >$ php xxx\/main.php\nstart.\n#0  Dog::bark() called at [\/Applications\/MAMP\/htdocs\/xxx\/main.php:28]\n#1  Main::bark(Array ([0] =&gt; Dog,[1] =&gt; Cat)) called at [\/Applications\/MAMP\/htdocs\/xxx\/main.php:38]\nbowwow\n#0  Cat::bark() called at [\/Applications\/MAMP\/htdocs\/xxx\/main.php:28]\n#1  Main::bark(Array ([0] =&gt; Dog,[1] =&gt; Cat)) called at [\/Applications\/MAMP\/htdocs\/xxx\/main.php:38]\nmeowmeow\n#0  Dog::bark() called at [\/Applications\/MAMP\/htdocs\/xxx\/main.php:33]\n#1  Main-&gt;dogBark() called at [\/Applications\/MAMP\/htdocs\/xxx\/main.php:39]\nbowwow<\/pre><\/div>\n\n\n\n<h2>\u30aa\u30ec\u30aa\u30ec backtrace<\/h2>\n\n\n\n<p><br>\u4fbf\u5229\u306a\u3053\u3068\u306b\u306f\u304b\u308f\u308a\u306a\u3044\u306e\u3060\u3051\u3069\u3001\u50d5\u306b\u306f\u3053\u308c\u304c\uff08\u5f15\u6570\u3067\u3044\u304f\u3089\u304b\u5236\u5fa1\u53ef\u80fd\u3068\u306f\u8a00\u3048\uff09<strong>\u5c11\u3057\u5197\u9577\u3067\u898b\u3065\u3089\u3044\u306e\u3067\u6b32\u3057\u3044\u60c5\u5831\u3060\u3051\u3092<\/strong>\u51fa\u529b\u3059\u308b\u30aa\u30ec\u30aa\u30ec backtrace \u3092\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002\u60c5\u5831\u306f <a href=\"https:\/\/www.php.net\/manual\/ja\/function.debug-backtrace.php\" data-type=\"URL\" data-id=\"https:\/\/www.php.net\/manual\/ja\/function.debug-backtrace.php\">debug_trace()<\/a> \u3067\u5165\u624b\u3067\u304d\u308b\u306e\u3067\u3053\u308c\u3092\u30b4\u30cb\u30e7\u30b4\u30cb\u30e7\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:php decode:true \" >$is_debug = true;\n\nfunction print_backtrace($limit = 2) {\n  global $is_debug;\n  if (!$is_debug) { return; }\n\n  $break = php_sapi_name() == 'cli' ? \"\\n\" : \"&lt;br&gt;\";\n  $info = debug_backtrace();\n  echo $break;\n  $output = array();\n\n  foreach ($info as $i =&gt; $trace) {\n    \/\/ if ($i == 0) { continue; } \u6a21\u5023\u3092\u76ee\u6307\u3059\u306a\u3089\u5165\u308c\u308b\n    if ($i &gt; $limit) { break; }\n    $file = preg_replace('\/(^.*)(\\\\\/.*?\\\\\/.*?\\.php)\/', '$2', $trace[\"file\"]);\n    $output[$i] = &lt;&lt;&lt;EOD\n      $file ({$trace[\"line\"]}) {$trace[\"class\"]}{$trace[\"type\"]}{$trace[\"function\"]} $break\n    EOD;\n  }\n  foreach (array_reverse($output) as $value) {\n    echo $value;\n  }\n}<\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u95a2\u6570\u306e\u8981\u70b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<ol><li>\u30b0\u30ed\u30fc\u30d0\u30eb\u306b\u5b9a\u7fa9\u3057\u305f $is_debug \u3067\u30c7\u30d0\u30c3\u30b0\u306e\u6642\u4ee5\u5916\u306f\u4f55\u3082\u3057\u306a\u3044<\/li><li><strong>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3068\u30d6\u30e9\u30a6\u30b6\u4e21\u65b9\u3067\u4f7f\u3046<\/strong>\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u6539\u884c\u65b9\u6cd5\u3092\u5909\u66f4\u3057\u3066\u3044\u308b\uff08debug_print_backtrace() \u3060\u3068\u30d6\u30e9\u30a6\u30b6\u3067\u6539\u884c\u3055\u308c\u306a\u304f\u3066\u898b\u8f9b\u304b\u3063\u305f\uff09<\/li><li>$limit \u3067\u3069\u306e\u968e\u5c64\u307e\u3067\u51fa\u529b\u3059\u308b\u304b\u9078\u3079\u308b\uff08debug_print_backtrace() \u3068\u540c\u3058\u4ed5\u69d8\uff09<\/li><li>\u51fa\u529b\u3092 <strong>\u30101\u3064\u4e0a\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\/\u30d5\u30a1\u30a4\u30eb\u540d (\u884c\u6570) \u30af\u30e9\u30b9\u540d::\u95a2\u6570\u540d \u6539\u884c\u3011<\/strong> \u3068\u3057\u305f<\/li><li>\u547c\u3073\u51fa\u3057\u9806\u3092\u9006\u304b\u3089\u8fbf\u308b\u3088\u3046\u306b\u3057\u305f<\/li><\/ol>\n\n\n\n<p>\u51fa\u529b\u7d50\u679c\u306f\u3053\u3046\u306a\u308b\u3002\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u30d5\u30eb\u30d1\u30b9\u3060\u3068\u898b\u8f9b\u304b\u3063\u305f\u304b\u3089\u305d\u308c\u3092\u5909\u3048\u305f\u304f\u3066\u6b63\u898f\u8868\u73fe\u30671\u3064\u4e0a\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3088\u308a\u524d\u306f\u524a\u9664\u3057\u305f\u304a\u304b\u3052\u3067\u7d50\u69cb\u898b\u3084\u3059\u304f\u306a\u3063\u305f\u3068\u601d\u3046\u3002\u53c2\u8003: <a href=\".\/?p=63\" data-type=\"URL\" data-id=\".\/?p=63\">\u3010PHP\u3011\u6b63\u898f\u8868\u73fe\u3092\u7528\u3044\u3066\u6587\u5b57\u5217\u3092\u64cd\u4f5c\u3059\u308b<\/a><br>\uff08print_backtrace() \u306e\u547c\u3073\u51fa\u3057\u5143\u60c5\u5831\u304c\u4e0d\u8981\u306a\u3089 foreach \u306e\u5148\u982d\u3067 if ($i == 0) { continue; } \u3059\u308b\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ php xxx\/main.php\nstart.\n\n  \/xxx\/main.php (38) Main::bark\n  \/xxx\/main.php (28) Dog::bark\n  \/xxx\/dog.php (6) print_backtrace\nbowwow\n\n  \/xxx\/main.php (38) Main::bark\n  \/xxx\/main.php (28) Cat::bark\n  \/xxx\/cat.php (6) print_backtrace\nmeowmeow\n\n  \/xxx\/main.php (39) Main-&gt;dogBark\n  \/xxx\/main.php (33) Dog::bark\n  \/xxx\/dog.php (6) print_backtrace\nbowwow<\/code><\/pre>\n\n\n\n<h2>\u3061\u306a\u307f\u306b<\/h2>\n\n\n\n<p>\u30b9\u30bf\u30c3\u30af\u30d5\u30ec\u30fc\u30e0\u3067\u306f\u306a\u304f<strong>\u73fe\u5728\u306e\u60c5\u5831\uff08\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u884c\u6570\uff09\u3060\u3051\u304c\u6b32\u3057\u3044\u5834\u5408<\/strong>\u306b\u306f __FILE__ , __LINE__ \u306a\u3069\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u540d\u524d<\/th><th>\u8aac\u660e<\/th><\/tr><\/thead><tbody><tr><td>__FUNCTION__<\/td><td>\u73fe\u5728\u306e\u95a2\u6570\u540d<\/td><\/tr><tr><td>__LINE__<\/td><td>\u73fe\u5728\u306e\u884c\u756a\u53f7<\/td><\/tr><tr><td>__FILE__<\/td><td>\u73fe\u5728\u306e\u30d5\u30a1\u30a4\u30eb\u540d<\/td><\/tr><tr><td>__CLASS__<\/td><td>\u73fe\u5728\u306e\u30af\u30e9\u30b9\u540d<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u3067\u306f debug_print_backtrace() \u3067\u30d0\u30c3\u30af\u30c8\u30ec\u30fc\u30b9\u3092\u8868\u793a\u3067\u304d\u308b\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u4f8b\u306e\u3088\u3046\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u3069\u3046\u3044\u3046\u9806\u756a\u3067\u5b9f\u884c\u3055\u308c\u305f\u304b\u3092\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002 \u4f8b\u3048\u3070\u3053\u3093\u306a\u611f\u3058\u306e3\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u3063\u305f&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[5],"tags":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":63,"url":"https:\/\/tech.for-easy-learning.com\/?p=63","url_meta":{"origin":86,"position":0},"title":"\u3010PHP\u3011\u6b63\u898f\u8868\u73fe\u3092\u7528\u3044\u3066\u6587\u5b57\u5217\u3092\u64cd\u4f5c\u3059\u308b","date":"2021\u5e744\u670823\u65e5","format":false,"excerpt":"PHP \u3067\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3046\u5834\u5408\u3001\u4ee5\u4e0b\u306e PCRE\u95a2\u6570 \u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u76ee\u7684\u306b\u5fdc\u3058\u3066\u4f7f\u3044\u5206\u3051\u308b\u3002 \u95a2\u2026","rel":"","context":"PHP","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27,"url":"https:\/\/tech.for-easy-learning.com\/?p=27","url_meta":{"origin":86,"position":1},"title":"\u3010SQLite\u3011phpLiteAdmin\u3092\u4f7f\u3046","date":"2021\u5e744\u670826\u65e5","format":false,"excerpt":"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3057\u3066 MySQL \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306b\u306f phpMyAdmin \u3092\u4f7f\u3044\u307e\u3059\u304c SQLite\u2026","rel":"","context":"SQLite","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19,"url":"https:\/\/tech.for-easy-learning.com\/?p=19","url_meta":{"origin":86,"position":2},"title":"\u3010WordPress\u3011\u30b5\u30d6\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u304a\u3044\u305fWordPress\u3092\u30eb\u30fc\u30c8\u306b\u8a2d\u5b9a\u3059\u308b","date":"2021\u5e744\u670826\u65e5","format":false,"excerpt":"\u30cd\u30c3\u30c8\u306b\u51fa\u56de\u3063\u3066\u3044\u308b WordPress \u306e\u8a2d\u5b9a\u3067\u306f\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304d\u305f wordpress \u30d5\u30a9\u30eb\u2026","rel":"","context":"WordPress","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4,"url":"https:\/\/tech.for-easy-learning.com\/?p=4","url_meta":{"origin":86,"position":3},"title":"\u3010Web\u3011Basic\u8a8d\u8a3c\u306e\u8a2d\u5b9a","date":"2021\u5e744\u670826\u65e5","format":false,"excerpt":"Web\u30b5\u30a4\u30c8\u306b\u516c\u958b\u3057\u3066\u3044\u308b\u3051\u3069\u4e0d\u7279\u5b9a\u591a\u6570\u306b\u898b\u3089\u308c\u3066\u306f\u56f0\u308b\u3082\u306e\u3063\u3066\u3042\u308a\u307e\u3059\u3088\u306d\u3002\u305d\u3046\u3044\u3063\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u2026","rel":"","context":"Web\u5168\u822c","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":264,"url":"https:\/\/tech.for-easy-learning.com\/?p=264","url_meta":{"origin":86,"position":4},"title":"\u3010iOS\/Swift\u3011Realm \u3067\u30c7\u30fc\u30bf\u3092\u78ba\u8a8d\u3059\u308b","date":"2021\u5e745\u67083\u65e5","format":false,"excerpt":"iOS \u3067\u624b\u8efd\u306b\u30c7\u30fc\u30bf\u3092\u6c38\u7d9a\u5316\u3059\u308b\u5834\u5408 UserDefaults \u304c\u4e00\u822c\u7684\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u5927\u91cf\u306e\u30c7\u2026","rel":"","context":"Swift","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":266,"url":"https:\/\/tech.for-easy-learning.com\/?p=266","url_meta":{"origin":86,"position":5},"title":"\u3010iOS\/Swift\u3011IGListKit \u30b5\u30f3\u30d7\u30eb\u306e GridSectionController \u3092\u4e00\u822c\u5316\u3059\u308b","date":"2021\u5e745\u67083\u65e5","format":false,"excerpt":"Instagram \u306e iOS \u30c1\u30fc\u30e0\u304c\u958b\u767a\u3057\u3066\u3044\u308b CollectionView \u3092\u4fbf\u5229\u306b\u6271\u3046\u305f\u3081\u2026","rel":"","context":"Swift","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=\/wp\/v2\/posts\/86"}],"collection":[{"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":23,"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":204,"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions\/204"}],"wp:attachment":[{"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.for-easy-learning.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}