{"id":78,"date":"2012-11-26T19:40:55","date_gmt":"2012-11-26T11:40:55","guid":{"rendered":"http:\/\/www.yeetrack.com\/post\/2012-11-26\/php%25E7%259A%2584%25E9%2594%2599%25E8%25AF%25AF%25E5%25A4%2584%25E7%2590%2586"},"modified":"2013-04-20T17:25:06","modified_gmt":"2013-04-20T09:25:06","slug":"php%e7%9a%84%e9%94%99%e8%af%af%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=78","title":{"rendered":"php\u7684\u9519\u8bef\u5904\u7406"},"content":{"rendered":"<p> &nbsp;\u7f16\u5199\u7684\u7a0b\u5e8f\u5728\u8fd0\u884c\u4e2d\u90fd\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e00\u4e9b\u9519\u8bef\u6216\u8005\u8b66\u544a\u7b49\uff0c\u5f53php\u89e3\u91ca\u5668\u89e3\u91ca\u6267\u884cphp\u6587\u4ef6\u65f6\uff0c\u5982\u679c\u9047\u5230php\u9519\u8bef\uff0c\u5c31\u4f1a\u5411\u5916\u629b\u51fa\u95ee\u9898<\/p>\n<p><!--more--><\/p>\n<p>\uff0c\u5177\u4f53\u6211\u4eec\u53ef\u4ee5\u5728php.ini\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u914d\u7f6e\u3002php\u9519\u8bef\u5206\u5f88\u591a\u7ea7\u522b\uff0c\u8be6\u7ec6\u5982\u4e0b\uff1a<\/p>\n<ul class=\"edui-filter-disc\">\n<li>\n<p>E_ERROR : \u81f4\u547d\u8fd0\u884c\u9519\u8bef\uff0c\u4f1a\u505c\u6b62\u811a\u672c\u8fd0\u884c<\/p>\n<\/li>\n<li>\n<p>E_WARNING : \u8fd0\u884c\u65f6\u7684\u8b66\u544a\u4fe1\u606f\uff0c\u4e0d\u4f1a\u505c\u6b62\u811a\u672c\u8fd0\u884c<\/p>\n<\/li>\n<li>\n<p>E_PARSE : \u8bed\u6cd5\u89e3\u6790\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>E_NOTICE : \u8fd0\u884c\u662f\u7684\u6d88\u606f\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>E_CORE_ERROR : \u7c7b\u4f3cE_ERROR\uff0c\u4f46\u662f\u4e0d\u5305\u62ecphp\u6838\u5fc3\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>E_CORE_WARNING : \u7c7b\u4f3cE_WARNING\uff0c\u4f46\u662f\u4e0d\u5305\u62ecphp\u6838\u5fc3\u8b66\u544a<\/p>\n<\/li>\n<li>\n<p>E_COMPILE_ERROR : \u81f4\u547d\u7f16\u8bd1\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>E_COMPILE_WARNING : \u81f4\u547d\u7f16\u8bd1\u8b66\u544a<\/p>\n<\/li>\n<li>\n<p>E_USER_ERROR : \u7528\u6237\u5bfc\u81f4\u7684\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>E_USER_WARNING : \u7528\u6237\u5bfc\u81f4\u7684\u8b66\u544a<\/p>\n<\/li>\n<li>\n<p>E_USER_NOTICE : \u7528\u6237\u5bfc\u81f4\u7684\u6d88\u606f<\/p>\n<\/li>\n<li>\n<p>E_ALL : \u6240\u6709\u7684\u9519\u8bef\u3001\u6d88\u606f\u548c\u6d88\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>E_SCRIPT : \u5173\u4e8ephp\u7248\u672c\u79fb\u690d\u7684\u517c\u5bb9\u6027\u548c\u64cd\u4f5c\u6027\u5efa\u8bae<\/p>\n<\/li>\n<\/ul>\n<p> &nbsp;&nbsp;\u5982\u679c\u7a0b\u5e8f\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u60f3\u770b\u5230php\u9519\u8bef\u6d88\u606f\uff0c\u8981\u5728php.ini\u6587\u4ef6\u4e2d\u5c06display_errors\u914d\u7f6e\u9879\u8bbe\u7f6e\u6210on\uff08\u6ce8\u610f\u5728\u7a0b\u5e8f\u4e0a\u7ebf\u8fd0\u884c\u65f6\uff0c\u4e00\u5b9a\u8981\u5c06display_errors\u5173\u6389\uff0c\u5426\u5219\u5bb9\u6613\u6cc4\u6f0f\u6709\u5173\u670d\u52a1\u5668\u7684\u4fe1\u606f\uff0c\u4e3a\u8fdb\u4e00\u6b65\u653b\u51fb\u9020\u6210\u94fa\u57ab\uff09\u3002\u6211\u4eec\u8fd8\u53ef\u4ee5\u5b9a\u4e49php\u62a5\u544a\u9519\u8bef\u7684\u7ea7\u522b\uff0c\u5177\u4f53\u5728error_reporting\u914d\u7f6e\u9879\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">&lt;html&gt;\n    &lt;head&gt;\n        &lt;title&gt;php\u9519\u8bef\u548c\u5f02\u5e38&lt;\/title&gt;\n        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html;charset=UTF-8&quot;&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;?php \n            echo ini_get(&quot;log_errors&quot;) . &quot;&lt;br \/&gt;&quot;;\n            echo ini_get(&quot;display_errors&quot;) . &quot;&lt;br \/&gt;&quot;;\n            ini_set(&quot;display_errors&quot;, 1); \/\/\u6253\u5f00php\u7684\u9519\u8bef\u8f93\u51fa\uff08\u6b63\u5f0f\u73af\u5883\u8981\u5173\u95ed\uff09\n            error_reporting(E_ALL&amp;~(E_WARNING | E_NOTICE));\/\/\u8bbe\u7f6ephp\u8f93\u51fa\u9519\u8bef\u7684\u7ea7\u522b,\u8f93\u5165\u975eE_WARNING\u548cE_NOTICE\u7ea7\u522b\u7684\u9519\u8bef\n            gettype($name);\/\/\u8c03\u7528\u6ca1\u6709\u5b9a\u4e49\u7684\u53d8\u91cf\n            gettype();\/\/\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u6ca1\u6709\u6307\u5b9a\u5fc5\u987b\u7684\u53c2\u6570\n            getName();\/\/\u8c03\u7528\u6ca1\u6709\u5b9a\u4e49\u7684\u51fd\u6570   \n        ?&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>\u5982\u4e0a\u9762\u4ee3\u7801\u5c31\u4f1a\u8f93\u5165getName()\u8fd9\u4e00\u884c\u4ee3\u7801\u629b\u51fa\u7684\u9519\u8bef\u4fe1\u606f\uff1a<\/p>\n<p>1<br \/>1<\/p>\n<p>( ! ) Fatal error: Call to undefined function getName() in \/home\/youthflies\/work\/workspace\/php\/test\/test3.php on line <em>15<\/em>Call Stack#TimeMemoryFunctionLocation10.0268126916{main}( )..\/test3.php<strong>:<\/strong>0<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u968f\u65f6\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u3001\u5c4f\u853d\u9519\u8bef\u8f93\u51fa\uff08\u9632\u6b62\u9ed1\u5ba2\u653b\u51fb\uff09\u3001\u6307\u5b9a\u53cb\u597d\u7684\u9519\u8bef\u9875\u9762\u3002\u4e00\u822c\u4f7f\u7528set_error_handler()\u51fd\u6570\u6765\u624b\u5de5\u6307\u5b9a\u9519\u8bef\u5904\u7406\u51fd\u6570\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">&lt;?php\n    \/\/\u4e3a\u4e86\u7f51\u7ad9\u5b89\u5168\uff0c\u4e00\u5b9a\u8981\u5c4f\u853d\u6389\u4e00\u5207\u7684\u9519\u8bef\u8f93\u51fa\n    error_reporting(0);\n                               \n    \/**\n     * \u81ea\u5b9a\u4e49Error_Handler\u51fd\u6570\uff0c\u4f5c\u4e3aset_error_handler()\u51fd\u6570\u7684\u56de\u8c03\u51fd\u6570,\u8be5\u51fd\u6570\u5fc5\u987b\u6709\u56db\u4e2a\u53c2\u6570\n     * @param   int $error_level    \u9519\u8bef\u7ea7\u522b\n     * @param   string  $error_message  \u9519\u8bef\u6d88\u606f\n     * @param   string  $file   \u53d1\u751f\u9519\u8bef\u7684\u6587\u4ef6\n     * @param   int $line   \u53d1\u751f\u9519\u8bef\u7684\u884c\u6570\n     *\/\n    function error_handler($error_level, $error_message, $file, $line)\n    {\n        $EXIT = FALSE;\n        switch ($error_level)\n        {\n            \/\/\u9519\u8bef\u7ea7\u522b\n            case E_ERROR:\n            case E_USER_ERROR:\n                $error_type = &quot;Fatal Error&quot;;\n                $EXIT = true;\n                break;\n                                           \n            \/\/\u63d0\u9192\u7ea7\u522b\n            case E_NOTICE:\n            case E_USER_NOTICE:\n                $error_type = &quot;Notice&quot;;\n                break;\n                                           \n            \/\/\u8b66\u544a\u7ea7\u522b\n            case E_WARNING:\n            case E_USER_WARNING:\n                $error_type = &quot; Warning&quot;;\n                break;\n                                           \n            \/\/\u5176\u4ed6\u672a\u77e5\u9519\u8bef\n            default:\n                $error_type = &quot;Unknown&quot;;\n                $EXIT = true;\n                break;\n        }\n        \/\/\u76f4\u63a5\u6253\u5370\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\uff0c\u4f46\u662f\u4e3a\u4e86\u5b89\u5168\uff0c\u4e00\u822c\u662f\u5199\u5165\u6587\u4ef6\uff0c\u6216\u8005\u6570\u636e\u5e93\n        printf(&quot;&lt;font clolr='#FF0000'&gt;&lt;b&gt;%s&lt;\/b&gt;&lt;\/font&gt;:%s in &lt;b&gt;%s&lt;\/b&gt; on line &lt;b&gt; %d &lt;\/b&gt;&lt;br&gt;n&quot;, $error_type, $error_message, $file, $line);\n        if($EXIT == true)\n            echo '&lt;script&gt;location=&quot;error.html&quot;&lt;\/script&gt;';\n    }\n    \/\/\u8bbe\u7f6e\u9519\u8bef\u5904\u7406\u51fd\u6570\n    set_error_handler('error_handler');\n                               \n    \/\/\u62a5\u672a\u5b9a\u4e49\u7684\u53d8\u91cfnotice\n    echo $name;\n    \/\/\u62a5\u96640\u8b66\u544a\n    echo 10\/0;\n    \/\/\u624b\u52a8\u629b\u51fa\u9519\u8bef\n    trigger_error('\u81f4\u547d\u9519\u8bef', E_USER_ERROR);\n?&gt;<\/pre>\n<p>\u901a\u8fc7\u66f4\u6539php.ini\u914d\u7f6e\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u9519\u8bef\u4fe1\u606f\u8f93\u51fa\u5230\u6307\u5b9a\u6587\u4ef6\u4e2d\uff1a<\/p>\n<p>error_reporting = E_ALL ;\u629b\u51fa\u6bcf\u4e00\u4e2a\u9519\u8bef\u3001\u8b66\u544a<\/p>\n<p>display_errors = Off ; \u5173\u95ed\u9519\u8bef\u5c55\u793a<\/p>\n<p>log_errors = On ;\u51b3\u5b9a\u65e5\u5fd7\u8bed\u53e5\u8bb0\u5f55\u7684\u4f4d\u7f6e<\/p>\n<p>log_errors_max_len = 1024 ;\u6bcf\u4e2a\u65e5\u5fd7\u9879\u7684\u6700\u5927\u957f\u5ea6<\/p>\n<p>error_log = \/home\/yourname\/work\/error.log ; \u6307\u5b9a\u9519\u8bef\u65e5\u5fd7\u6587\u4ef6<\/p>\n<p>\u4fee\u6539\u5b8c\u6bd5\u540e\uff0c\u91cd\u542fWeb\u670d\u52a1\u5668\uff0c\u5373\u53ef\u751f\u6548\u3002\u7136\u540e\u518d\u8fd0\u884c\u542b\u6709\u9519\u8bef\u7684php\u4ee3\u7801\uff0c\u9519\u8bef\u4fe1\u606f\u5c31\u4f1a\u88ab\u5199\u5165\u5230error.log\u4e2d\u3002<\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9519\u8bef\u4fe1\u606f\uff0cerror_log()\u51fd\u6570\u5141\u8bb8\u6211\u4eec\u81ea\u5b9a\u4e49\u9519\u8bef\u3002<\/p>\n<pre config=\"brush:php;toolbar:false;\">error_log(&quot;This is an error&quot;, 3, &quot;\/home\/yourname\/work\/error.log&quot;);<\/pre>\n<p>\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u9519\u8bef\u5185\u5bb9\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\u9519\u8bef\u4fe1\u606f\u7684\u8f93\u51fa\u4f4d\u7f6e\uff0c\u5982\u679c\u7559\u7a7a\uff0c\u5c31\u9ed8\u8ba4php.ini\u6307\u5b9a\u7684\u4f4d\u7f6e\uff0c0\u8868\u793a\u64cd\u4f5c\u7cfb\u7edf\u65e5\u5fd7\uff0c1\u8868\u793a\u4f7f\u7528php mail()\u51fd\u6570\u53d1\u9001\u51fa\u53bb\uff0c2\u8868\u793a\u5c06\u9519\u8bef\u6d88\u606f\u53d1\u9001\u5230tcp\uff08\u6b64\u65f6\u7b2c\u4e09\u4e2a\u53c2\u6570\u8868\u793a\u76ee\u6807IP\u53ca\u7aef\u53e3\uff09\uff0c3\u8868\u793a\u5b58\u5230\u672c\u673a\u6587\u4ef6\u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\u7f16\u5199\u7684\u7a0b\u5e8f\u5728\u8fd0\u884c\u4e2d\u90fd\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e00\u4e9b\u9519\u8bef\u6216\u8005\u8b66\u544a\u7b49\uff0c\u5f53php\u89e3\u91ca\u5668\u89e3\u91ca\u6267\u884cphp\u6587\u4ef6\u65f6\uff0c\u5982\u679c\u9047\u5230php\u9519\u8bef\uff0c\u5c31\u4f1a\u5411\u5916\u629b\u51fa\u95ee\u9898<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[24,7],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-coding","tag-php","tag-7"],"views":3150,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":388,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions\/388"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}