{
    "componentChunkName": "component---src-templates-blog-post-jsx",
    "path": "/post/display-error-temporary-in-php/",
    "result": {"data":{"site":{"siteMetadata":{"title":"WEB EGG","author":"Leko - CTO at Yuimedi"}},"markdownRemark":{"id":"d749dd78-33ed-570c-acd0-65dd6cb1fae2","excerpt":"こんにちは。 私はさくらVPS2Gプランで開発をしているのですが、 デフォルトだとphp_iniファイルでdisplay_errorsがOFF…","html":"<p>こんにちは。 私はさくらVPS2Gプランで開発をしているのですが、 デフォルトだとphp_iniファイルでdisplay_errorsがOFFになっているようです。 セキュリティ的にこちらのほうが好ましいのですが、 エラー潰しをしている時に何も出力してくれないのは、時間効率があまり良くありません。 一時的で良いのでエラー出せないかな？ ローカルで動作させてからアップロードしろよ、という話なのですが、 今回はphpの関数ini_setを用いて一時的にエラーを出力する方法を残します。</p>\n<!--more-->\n<h2 id=\"ini_set\" style=\"position:relative;\"><a href=\"#ini_set\" aria-label=\"ini_set permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ini_set</h2>\n<blockquote>\n<p>string ini_set ( string $varname , string $newvalue )<br>\n指定した設定オプションの値を設定します。<br>\n設定オプションは、スクリプトの実行中は新しい値を保持し、スクリプト終了時に元の値へ戻されます。</p>\n<p><a href=\"http://php.net/manual/ja/function.ini-set.php\" target=\"_blank\">PHP: ini_set – Manual</a></p>\n</blockquote>\n<p>と公式リファレンスにあるので、これで変更してみましょう。</p>\n<h2 id=\"エラーを出力しない場合のサンプル\" style=\"position:relative;\"><a href=\"#%E3%82%A8%E3%83%A9%E3%83%BC%E3%82%92%E5%87%BA%E5%8A%9B%E3%81%97%E3%81%AA%E3%81%84%E5%A0%B4%E5%90%88%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB\" aria-label=\"エラーを出力しない場合のサンプル permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>エラーを出力しない場合のサンプル</h2>\n<p>まずは動かないサンプルを書きます。</p>\n<div class=\"gatsby-highlight\" data-language=\"php\"><pre class=\"language-php\"><code class=\"language-php\"><span class=\"token php language-php\"><span class=\"token delimiter important\">&lt;?php</span>\n\n<span class=\"token keyword\">require_once</span><span class=\"token punctuation\">(</span><span class=\"token string double-quoted-string\">\"XXX.php\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//存在しないファイル </span><span class=\"token delimiter important\">?></span></span>;</code></pre></div>\n<p>これをブラウザで表示しようとすると、下の画像のような画面になります。</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 406px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/256e8df255c8c420cbaafd5d5464bdbb/e33ef/20130107_faild.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 61.67664670658682%; position: relative; bottom: 0; left: 0; background-image: url('data:image/svg+xml,%3csvg%20xmlns=\\'http://www.w3.org/2000/svg\\'%20width=\\'400\\'%20height=\\'246\\'%20viewBox=\\'0%200%20400%20246\\'%20preserveAspectRatio=\\'none\\'%3e%3cpath%20d=\\'M395%203c2%202%202%20235%200%20237S8%20242%206%20240L5%20129%204%2012V5L2%208c-2%202-2%208-2%20120v118h401V125c0-119-1-120-2-121-3-2-6-3-4-1M228%2021c-11%208-6%2024%207%2024%204%200%207-2%206-3h-2c-2%200-3-1-1-3l1-1v-4c1-3-1-6-4-6l3-1c8%200%209%200%207-3-3-5-12-6-17-3M28%2026l-2%202c-2%200-2%201-2%202l2%201c1%200%202%201%202%203%201%203%203%203%204%200%200-3%201-3%202-3%204%201%202%208-3%209v2c3%204%209-2%209-8%200-2%201-3%202-3%203-1%203-2%200-3l-2-2-1-2-2%202-2%202c-2%200-3-1-3-2l-2-2-2%202m93%202l3%202c3%200%203%201%203%204%200%204%200%204-4%204-7%201-3%203%207%203%209%200%2013-2%205-3-4%200-4%200-4-4s0-4%203-4l4-2c0-1-2-2-9-2s-8%200-8%202m163%201c-3%206%202%2012%208%209%202-1%203-7%201-10-2-2-7-1-9%201m-141%203l7%201c6%200%206%200%205%202l-4%204c-5%202-4%202-3%203%202%203%209-2%2012-8%201-4%201-4-9-4-6%200-8%200-8%202M27%2072c-2%202-1%203%206%203l8%202h2a195%20195%200%200146%200c2-2%202-2%202%200h2l16-1h16v-5H76l-49%201m133%2027l-1%205c0%204%200%205%201%204h2c1%201%207%201%208-1h-4l2-1%201-3h1l1%203c0%203%200%203%205%203s7-1%204-2v-7c-1-1-2-2-3-1h-4c0-2-2-1-2%201-1%202-1%202-2%201%200-2-8-4-9-2m36%2053l-1%206c0%202%203%202%2030%202l30-1-1-1c-2%200-5-4-5-6h3c1%201%203-1%202-3h-9c-1%201%200%201%201%201%202%200%202%200%201%202l1%204c2%202%202%202-3%202s-5%200-4-2l1-2-1%201c-1%202-3%201-3-1l-1-3v-2l-1-2-4%2010-1%201-1-1c0-3-3-10-5-10-1%200-2%202%200%202v3c-1%202-1%202-2%201-1-3-3-2-2%200%200%203-2%205-5%205h-2l2-2c2-2%202-6%200-6v1l-1%201-1-2c0-2-3-4-4-2v1c3%200%202%201%200%203l-2%203c0%202%200%202%202%202h2l-3%201c-2%200-3%200-2-1l-1-1c-2%201-2%200-2-1s0-2%201-1l1-3v-4h-10v5m-94%2043c-1%202-1%203%201%203l2%202h-4c0%202%203%202%205%201h9c0%202%204%201%204-1%202-5%200-9-4-6h-3c-1-2-3-1-4%201l-2%202-2-1v-1h1l1-1c0-2-4-1-4%201m68%202c0%203%200%203-1%201-1-3-4-4-5-2-1%201-1%201%201%201s2%200%201%201c-3%201-4%201-4-1-1-2-7-3-8-1h-3c-2-2-6%201-5%203%201%203%204%204%206%201h1l1%202%201-2c0-4%202-4%202%200l1%203v-3c0-4%203-4%203-1%200%202%201%203%205%203%205%200%205-1%205-6-1-3-1-3-1%201\\'%20fill=\\'%23d3d3d3\\'%20fill-rule=\\'evenodd\\'/%3e%3c/svg%3e'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/256e8df255c8c420cbaafd5d5464bdbb/5251b/20130107_faild.webp 167w,\n/static/256e8df255c8c420cbaafd5d5464bdbb/7390e/20130107_faild.webp 334w,\n/static/256e8df255c8c420cbaafd5d5464bdbb/09a6f/20130107_faild.webp 406w\"\n              sizes=\"(max-width: 406px) 100vw, 406px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/256e8df255c8c420cbaafd5d5464bdbb/21521/20130107_faild.png 167w,\n/static/256e8df255c8c420cbaafd5d5464bdbb/86d36/20130107_faild.png 334w,\n/static/256e8df255c8c420cbaafd5d5464bdbb/e33ef/20130107_faild.png 406w\"\n            sizes=\"(max-width: 406px) 100vw, 406px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/256e8df255c8c420cbaafd5d5464bdbb/e33ef/20130107_faild.png\"\n            alt=\"2013010\"\n            title=\"2013010\"\n            loading=\"lazy\"\n            decoding=\"async\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h2 id=\"エラーを出力するサンプル\" style=\"position:relative;\"><a href=\"#%E3%82%A8%E3%83%A9%E3%83%BC%E3%82%92%E5%87%BA%E5%8A%9B%E3%81%99%E3%82%8B%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB\" aria-label=\"エラーを出力するサンプル permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>エラーを出力するサンプル</h2>\n<p>このスクリプトの何処にエラーが出てるのかを出力してみます。</p>\n<div class=\"gatsby-highlight\" data-language=\"php\"><pre class=\"language-php\"><code class=\"language-php\"><span class=\"token php language-php\"><span class=\"token delimiter important\">&lt;?php</span>\n\n<span class=\"token function\">ini_set</span><span class=\"token punctuation\">(</span><span class=\"token string single-quoted-string\">'display_errors'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">require_once</span><span class=\"token punctuation\">(</span><span class=\"token string double-quoted-string\">\"XXX.php\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//存在しないファイル </span><span class=\"token delimiter important\">?></span></span>;</code></pre></div>\n<p>ini_setの１行を追加してブラウザを開いてみます。 すると、下の画像のようにエラーが出力されます！</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 553px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/88f0c9930ab38f92f9cb43720710652c/74cfa/20130107_success.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 23.353293413173652%; position: relative; bottom: 0; left: 0; background-image: url('data:image/svg+xml,%3csvg%20xmlns=\\'http://www.w3.org/2000/svg\\'%20width=\\'400\\'%20height=\\'93\\'%20viewBox=\\'0%200%20400%2093\\'%20preserveAspectRatio=\\'none\\'%3e%3cpath%20d=\\'M73%2063l-1%204-1-3c1-3%200-5-2-3h-4l-3%201%202%201h1l-1%202c1%200%202%200%201%201l-3-2c-4-5-7-4-7%202%200%202%200%204%201%203l2-1%203-2h1c1%202%206%203%206%201v-3c0-2%200-2%201%201s5%205%205%201l2-3c1-1%201-1%201%201l1%204%201-3c0-3-1-4-2-4l-3-1c-1-1-1%200-1%203\\'%20fill=\\'%23d3d3d3\\'%20fill-rule=\\'evenodd\\'/%3e%3c/svg%3e'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/88f0c9930ab38f92f9cb43720710652c/5251b/20130107_success.webp 167w,\n/static/88f0c9930ab38f92f9cb43720710652c/7390e/20130107_success.webp 334w,\n/static/88f0c9930ab38f92f9cb43720710652c/e58ce/20130107_success.webp 553w\"\n              sizes=\"(max-width: 553px) 100vw, 553px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/88f0c9930ab38f92f9cb43720710652c/21521/20130107_success.png 167w,\n/static/88f0c9930ab38f92f9cb43720710652c/86d36/20130107_success.png 334w,\n/static/88f0c9930ab38f92f9cb43720710652c/74cfa/20130107_success.png 553w\"\n            sizes=\"(max-width: 553px) 100vw, 553px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/88f0c9930ab38f92f9cb43720710652c/74cfa/20130107_success.png\"\n            alt=\"2013010\"\n            title=\"2013010\"\n            loading=\"lazy\"\n            decoding=\"async\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>※注意 ただし、Parse error（多くの場合文法ミス）だとプログラム自体が実行できないので、 ini_setも当然実行されず。。 実行前エラーは表示できません。 そこは目勘を鍛えて発見しましょう。</p>","timeToRead":2,"frontmatter":{"title":"PHPで一時的にエラーを表示する方法","tags":["PHP"],"date":"January 07, 2013","featuredImage":{"childImageSharp":{"fluid":{"tracedSVG":"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='150'%20viewBox='0%200%20400%20150'%20preserveAspectRatio='none'%3e%3cpath%20d='M0%2075v75h401V0H0v75m186%2010c-4%203-2%2011%202%2012%203%200%205-2%205-7%200-6-4-9-7-5'%20fill='%23d3d3d3'%20fill-rule='evenodd'/%3e%3c/svg%3e","aspectRatio":2.672,"src":"/static/31cb6003180407ae5dc3b0bef244e2ca/4fe8c/featured-image.jpg","srcSet":"/static/31cb6003180407ae5dc3b0bef244e2ca/466a3/featured-image.jpg 334w,\n/static/31cb6003180407ae5dc3b0bef244e2ca/4fe8c/featured-image.jpg 600w","srcWebp":"/static/31cb6003180407ae5dc3b0bef244e2ca/ad85c/featured-image.webp","srcSetWebp":"/static/31cb6003180407ae5dc3b0bef244e2ca/cd98f/featured-image.webp 334w,\n/static/31cb6003180407ae5dc3b0bef244e2ca/ad85c/featured-image.webp 600w","sizes":"(max-width: 600px) 100vw, 600px"}}}}}},"pageContext":{"slug":"/display-error-temporary-in-php/","previous":{"fields":{"slug":"/fix-require-relative-path-of-php/"},"frontmatter":{"title":"phpでrequire_onceするときに相対パスでハマった","tags":["PHP"]}},"next":{"fields":{"slug":"/how-to-treat-ready-event-in-jq-mobile/"},"frontmatter":{"title":"jQueryMobileでは$(function(){});ではなくpageinitとpageshowを使い分けるべき","tags":["jQuery","jQuery mobile"]}}}},
    "staticQueryHashes": ["2585454260","2954598359"]}