{"id":35,"date":"2025-03-03T19:54:52","date_gmt":"2025-03-03T19:54:52","guid":{"rendered":"https:\/\/phpcodechecker.org\/blog\/?p=35"},"modified":"2025-07-03T20:10:16","modified_gmt":"2025-07-03T20:10:16","slug":"display-php-errors-and-warnings","status":"publish","type":"post","link":"https:\/\/phpcodechecker.org\/blog\/display-php-errors-and-warnings\/","title":{"rendered":"How to Display PHP Errors and Warnings?"},"content":{"rendered":"\n<p>Are your PHP scripts not working, but you&#8217;re seeing a blank page? Don\u2019t worry \u2014 this is common when <strong>PHP errors and warnings<\/strong> are turned off.<\/p>\n\n\n\n<p>Learning <strong>how to display PHP errors<\/strong> is essential for debugging and fixing problems quickly. In this beginner-friendly tutorial, you\u2019ll learn how to <strong>enable PHP error reporting<\/strong>, show <strong>PHP warnings<\/strong>, and set up your server to make debugging easier.<\/p>\n\n\n\n<p>Whether you&#8217;re using XAMPP, MAMP, or a live server, this guide will help you turn on full PHP error visibility step by step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Display PHP Errors?<\/h2>\n\n\n\n<p>Showing errors helps you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Spot bugs and fix them fast<\/li>\n\n\n\n<li>Understand what\u2019s going wrong<\/li>\n\n\n\n<li>Improve code quality<\/li>\n\n\n\n<li>Save time during development<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. Show Errors with PHP Code<\/h2>\n\n\n\n<p>Add these lines at the top of your PHP file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ini_set('display_errors', 1);<br>ini_set('display_startup_errors', 1);<br>error_reporting(E_ALL);<\/code><\/pre>\n\n\n\n<p>This will make PHP show all errors and warnings on the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Show Errors Using <code>php.ini<\/code> (Server Settings)<\/h2>\n\n\n\n<p>If you want errors to show on all files:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open your <code>php.ini<\/code> file<\/li>\n\n\n\n<li>Find and change:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>display_errors = On<br>display_startup_errors = On<br>error_reporting = E_ALL<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Restart your server (Apache, Nginx, etc.)<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">3. Log Errors Instead (Safe for Live Sites)<\/h2>\n\n\n\n<p>For live (production) websites, don\u2019t show errors to users. Instead, log them like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>display_errors = Off<br>log_errors = On<br>error_log = \/path\/to\/php-error.log<\/code><\/pre>\n\n\n\n<p>This keeps your site safe while you still get the error info.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Test Example<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php<br>ini_set('display_errors', 1);<br>error_reporting(E_ALL);<br><br>\/\/ Intentional error<br>echo $undefined_var;<\/code><\/pre>\n\n\n\n<p>This will show:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Warning: Undefined variable&#8230;<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Showing PHP errors helps you find bugs fast. Use <code>ini_set()<\/code> during development, and switch to logging on live sites to stay secure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are your PHP scripts not working, but you&#8217;re seeing a blank page? Don\u2019t worry \u2014 this is common when PHP errors and warnings are turned off. Learning how to display PHP errors is essential for debugging and fixing problems quickly. In this beginner-friendly tutorial, you\u2019ll learn how to enable PHP error reporting, show PHP warnings, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-guides","category-debugging"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":1,"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":36,"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions\/36"}],"wp:attachment":[{"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpcodechecker.org\/blog\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}