{"id":191887,"date":"2020-06-01T08:29:18","date_gmt":"2020-06-01T00:29:18","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=191887"},"modified":"2020-05-20T09:29:38","modified_gmt":"2020-05-20T01:29:38","slug":"php-error","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/php-error.html","title":{"rendered":"PHP\u5173\u95ed\u8c03\u8bd5\u6a21\u5f0f\uff0c\u5c4f\u853d\u9519\u8bef"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u7f16\u5199 PHP \u4ee3\u7801\u7684\u65f6\u5019\u96be\u514d\u4f1a\u51fa\u73b0\u9519\u8bef\uff0c\u5f53\u5f88\u591a\u9519\u8bef\u4fe1\u606f\u5806\u79ef\u5230\u4e00\u8d77\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u4f7f\u6211\u4eec\u611f\u5230\u53cd\u611f\uff0c\u800c\u4e14\u9519\u8bef\u4fe1\u606f\u8fd8\u4f1a\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002\u6700\u91cd\u8981\u7684\u662f\uff0c\u5982\u679c\u8fd9\u4e9b\u9519\u8bef\u88ab\u6709\u5fc3\u4eba\u58eb\u770b\u5230\u7684\u8bdd\uff0c\u53ef\u80fd\u5bf9\u6574\u4e2a\u7a0b\u5e8f\u5e26\u6765\u5a01\u80c1\uff0c\u90a3\u4e48\u6211\u4eec\u5e94\u8be5\u5982\u4f55\u5c4f\u853d PHP \u4e2d\u7684\u9519\u8bef\u5462\uff1f<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

PHP \u4e2d\u5c4f\u853d\u9519\u8bef\u7684\u65b9\u6cd5\u67093\u4e2d\uff0c\u4e0b\u9762\u5c31\u6765\u5206\u522b\u4ecb\u7ecd\u4e00\u4e0b\u3002<\/p>\n

\u4f7f\u7528\u9519\u8bef\u63a7\u5236\u8fd0\u7b97\u7b26\uff1a@<\/strong><\/span><\/div>\n

PHP \u652f\u6301\u4f7f\u7528\u9519\u8bef\u63a7\u5236\u8fd0\u7b97\u7b26@\u3002\u5c06\u5176\u653e\u7f6e\u5728\u4e00\u4e2a PHP \u8868\u8fbe\u5f0f\u4e4b\u524d\uff0c\u8be5\u8868\u8fbe\u5f0f\u53ef\u80fd\u4ea7\u751f\u7684\u4efb\u4f55\u9519\u8bef\u4fe1\u606f\u90fd\u5c06\u88ab\u5ffd\u7565\u6389\u3002<\/p>\n

\u5982\u679c\u7528 set_error_handler() \u8bbe\u5b9a\u4e86\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u5904\u7406\u51fd\u6570\uff0c\u8fd9\u4e2a\u9519\u8bef\u5904\u7406\u51fd\u6570\u4ecd\u7136\u4f1a\u88ab\u8c03\u7528\uff0c\u800c\u5982\u679c\u5728\u51fa\u9519\u8bed\u53e5\u524d\u4f7f\u7528\u4e86@\u7684\u8bdd\uff0c\u9519\u8bef\u5904\u7406\u51fd\u6570\u5c06\u8fd4\u56de 0\u3002<\/p>\n

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c@\u8fd0\u7b97\u7b26\u53ea\u5bf9\u8868\u8fbe\u5f0f\u6709\u6548\u3002\u7b80\u5355\u6765\u8bf4\u5c31\u662f\uff0c\u5982\u679c\u80fd\u4ece\u67d0\u5904\u5f97\u5230\u503c\uff0c\u5c31\u80fd\u5728\u5b83\u524d\u9762\u52a0\u4e0a @ \u8fd0\u7b97\u7b26\u3002\u4f8b\u5982\u53ef\u4ee5\u5728\u53d8\u91cf\u3001\u51fd\u6570\u3001include \u8c03\u7528\u3001\u5e38\u91cf\u7b49\u7b49\u4e4b\u524d\u4f7f\u7528 @ \u8fd0\u7b97\u7b26\uff0c\u4f46\u4e0d\u80fd\u628a\u5b83\u653e\u5728\u51fd\u6570\u6216\u7c7b\u7684\u5b9a\u4e49\u4e4b\u524d\uff0c\u4e5f\u4e0d\u80fd\u7528\u4e8e\u6761\u4ef6\u7ed3\u6784\u4f8b\u5982 if \u548c foreach \u7b49\u8bed\u53e5\u524d\u3002<\/p>\n

@\u8fd0\u7b97\u7b26\u5bf9\u4e8e\u53ef\u4ee5\u5bfc\u81f4\u7a0b\u5e8f\u7ec8\u6b62\u7684\u4e25\u91cd\u9519\u8bef\u4e5f\u662f\u6709\u6548\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5982\u679c\u5728\u67d0\u4e2a\u4e0d\u5b58\u5728\u6216\u8005\u6572\u9519\u4e86\u5b57\u6bcd\u7684\u51fd\u6570\u8c03\u7528\u524d\u7528\u4e86@\u6765\u6291\u5236\u9519\u8bef\u4fe1\u606f\uff0c\u90a3\u4e48\u7a0b\u5e8f\u5c06\u6ca1\u6709\u4efb\u4f55\u63d0\u793a\u7684\u6b7b\u5728\u90a3\u91cc\u3002<\/p>\n

\u3010\u793a\u4f8b\u3011\u4f7f\u7528 @ \u9519\u8bef\u63a7\u5236\u8fd0\u7b97\u7b26\u5c4f\u853d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002<\/p>\n

<?php\r\n    $link = @mysqli_connect(\"127.0.0.1\", \"my_user\", \"my_password\", \"my_db\") or die('\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\uff01');\r\n?><\/pre>\n

\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\uff01<\/p>\n

\u4f7f\u7528 error_reporting() \u51fd\u6570\u5c4f\u853d\u9519\u8bef<\/strong><\/span><\/div>\n

PHP \u6709\u8bf8\u591a\u9519\u8bef\u7ea7\u522b\uff0c\u4f7f\u7528 error_reporting() \u51fd\u6570\u53ef\u4ee5\u8bbe\u7f6e PHP \u4f1a\u62a5\u544a\u4f55\u79cd\u9519\u8bef\uff0c\u51fd\u6570\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n

error_reporting([int $level])\r\n<\/pre>\n

\u5176\u4e2d\u53c2\u6570 $level \u4e3a\u8bbe\u7f6e\u9519\u8bef\u7ea7\u522b\uff0c\u5177\u4f53\u53ef\u4ee5\u4f7f\u7528\u7684\u503c\u53ef\u4ee5\u5728\u300aPHP\u9519\u8bef\u7ea7\u522b\u300b\u4e00\u8282\u4e2d\u67e5\u770b\u3002\u5982\u679c\u5c06 $level \u8bbe\u7f6e\u4e3a 0\uff0c\u5c06\u5173\u95ed\u6240\u6709 PHP \u9519\u8bef\u62a5\u544a\uff1b\u5982\u679c\u8bbe\u7f6e\u4e3a -1\uff0c\u5c06\u8fd4\u56de\u6240\u6709\u7684\u9519\u8bef\u62a5\u544a\u3002<\/p>\n

\u3010\u793a\u4f8b\u3011\u4f7f\u7528 error_reporting() \u51fd\u6570\u5c4f\u853d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002<\/p>\n

<?php\r\n    error_reporting(0);\r\n    $link = mysqli_connect(\"127.0.0.1\", \"my_user\", \"my_password\", \"my_db\") or die('\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\uff01');\r\n?><\/pre>\n
\u901a\u8fc7 display_errors \u53c2\u6570\u5c4f\u853d\u9519\u8bef<\/strong><\/span><\/div>\n

\u8fd9\u79cd\u65b9\u6cd5\u5e94\u8be5\u662f\u6700\u5f7b\u5e95\u7684\u4e00\u79cd\u89e3\u51b3\u529e\u6cd5\uff0c\u56e0\u4e3a\u524d\u4e24\u79cd\u65b9\u6cd5\u53ea\u80fd\u4f5c\u7528\u4e8e\u5355\u884c\u6216\u8005\u5355\u4e2a\u6587\u4ef6\uff0c\u800c\u8fd9\u4e2a\u5219\u662f\u4f5c\u7528\u4e8e\u6240\u6709\u7684 PHP \u6587\u4ef6\u3002<\/p>\n

\u5177\u4f53\u7684\u64cd\u4f5c\u65b9\u6cd5\u5c31\u662f\uff0c\u6253\u5f00 php.ini \u914d\u7f6e\u6587\u4ef6\uff0c\u5728\u5176\u4e2d\u641c\u7d22 display_errors\uff0c\u7136\u540e\u5c06 display_errors \u7684\u503c\u8bbe\u7f6e\u4e3a Off \u5373\u53ef\u5173\u95ed\u6240\u6709\u7684 PHP \u9519\u8bef\u62a5\u544a\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

; This directive controls whether or not and where PHP will output errors,\r\n; notices and warnings too. Error output is very useful during development, but\r\n; it could be very dangerous in production environments. Depending on the code\r\n; which is triggering the error, sensitive information could potentially leak\r\n; out of your application such as database usernames and passwords or worse.\r\n; For production environments, we recommend logging errors rather than\r\n; sending them to STDOUT.\r\n; Possible Values:\r\n;   Off = Do not display any errors\r\n;   stderr = Display errors to STDERR (affects only CGI\/CLI binaries!)\r\n;   On or stdout = Display errors to STDOUT\r\n; Default Value: On\r\n; Development Value: On\r\n; Production Value: Off\r\n; http:\/\/php.net\/display-errors\r\ndisplay_errors = Off\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

PHP \u4e2d\u5c4f\u853d\u9519\u8bef\u7684\u65b9\u6cd5\u67093\u4e2d\uff0c\u4e0b\u9762\u5c31\u6765\u5206\u522b\u4ecb\u7ecd\u4e00\u4e0b\u3002 PHP \u652f\u6301\u4f7f\u7528\u9519\u8bef\u63a7\u5236\u8fd0\u7b97\u7b26@\u3002\u5c06\u5176\u653e\u7f6e\u5728\u4e00\u4e2a PH […]<\/p>\n","protected":false},"author":1479,"featured_media":11223,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-191887","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=191887"}],"version-history":[{"count":9,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191887\/revisions"}],"predecessor-version":[{"id":192754,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191887\/revisions\/192754"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/11223"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=191887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=191887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=191887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}