{"id":9092,"date":"2026-05-17T21:55:38","date_gmt":"2026-05-17T16:25:38","guid":{"rendered":"https:\/\/www.veeble.com\/kb\/?p=9092"},"modified":"2026-05-17T21:55:38","modified_gmt":"2026-05-17T16:25:38","slug":"website-broke-after-php-upgrade","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/website-broke-after-php-upgrade\/","title":{"rendered":"Why Your Website Broke After a PHP Upgrade and How to Fix It"},"content":{"rendered":"\n<p>PHP 8 introduced stricter syntax enforcement that silently breaks code written for PHP 7.4. Things the older interpreter accepted without complaint, like unquoted constant names, bare array keys, and unquoted format strings, now throw fatal errors and take your site down. This guide covers the most common causes and how to fix them.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-know-if-php-is-the-cause\">How to Know If PHP Is the Cause<\/h2>\n\n\n<p>Your site may show a blank page, load only partially, or show a server error. If the timing lines up with a server migration or a PHP version change, that&#8217;s your first clue.<\/p>\n\n\n\n<p>Check your PHP error log from the site folder. If you see lines like these, PHP version is the cause:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-6690db01f0b1db19e4816abb975f0c27\"><code>PHP Fatal error: Uncaught Error: Undefined constant \"SCRIPT_ROOT\"\nPHP Fatal error: Uncaught Error: Undefined constant \"Y\"\nPHP Fatal error: Uncaught Error: Undefined constant \"email\"<\/code><\/pre>\n\n\n\n<p>These all point to the same type of issue: code that worked fine on PHP 7.4 but fails on PHP 8.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"the-most-common-breaking-changes\">The Most Common Breaking Changes<\/h2>\n\n<h3 class=\"wp-block-heading\" id=\"unquoted-constant-names-in-define\">Unquoted Constant Names in define()<\/h3>\n\n\n<p>This is probably the most common one. In PHP 7, you could write this, and it would work:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-121cee284324e255b368138ceb1b53e4\"><code>\/\/ \u274c Broken on PHP 8\ndefine(SCRIPT_ROOT, \"https:\/\/yoursite.com\/\");<\/code><\/pre>\n\n\n\n<p>PHP 8 throws a fatal error because <code>SCRIPT_ROOT<\/code> is not a quoted string. It tries to find a constant called <code>SCRIPT_ROOT<\/code> before it has been defined.<\/p>\n\n\n\n<p>The fix is simple, just add quotes around the constant name:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-fb1ac36940f4f3ee17fc9f1b519423ba\"><code>\/\/ \u2705 Works on both PHP 7 and PHP 8\ndefine('SCRIPT_ROOT', \"https:\/\/yoursite.com\/\");<\/code><\/pre>\n\n\n\n<p>Same rule applies everywhere you use <code>define()<\/code>. The first argument must always be a quoted string.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"2-unquoted-array-keys\">2. Unquoted Array Keys<\/h3>\n\n\n<p>In PHP 7, using bare words as array keys was allowed:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-1ff02a7d9994fd220c94a26890933313\"><code>\/\/ \u274c Broken on PHP 8\n$_SESSION&#091;email]\n$_COOKIE&#091;username]\n$_POST&#091;phone]<\/code><\/pre>\n\n\n\n<p>PHP 8 treats email, username, and phone as constants, and since they are not defined, it throws a fatal error.<\/p>\n\n\n\n<p>Always quote your array keys:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9b3150e1ad9421e2dc6dcd3f550637e0\"><code>\/\/ \u2705 Correct\n$_SESSION&#091;'email']\n$_COOKIE&#091;'username']\n$_POST&#091;'phone']<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"3-unquoted-strings-in-date-calls\">3. Unquoted Strings in date () Calls<\/h3>\n\n\n<p>This one shows up as <code>Undefined constant \"Y\"<\/code> in your error log. It happens when the date format string is passed without quotes:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-8ef24b5cde09f9744a0fa7ae763e77fe\"><code>\/\/ \u274c Broken on PHP 8\necho date(Y);\necho date(Y-m-d);<\/code><\/pre>\n\n\n\n<p>Again, PHP 8 tries to look up <code>Y<\/code> as a constant and fails. The fix:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-c52a5f573211895cfd865699ddb98fed\"><code>\/\/ \u2705 Correct\necho date('Y');\necho date('Y-m-d');<\/code><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"quick-reference-table\">Quick Reference Table<\/h2>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Error in Log<\/th><th>What It Means<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>Undefined constant \"SCRIPT_ROOT\"<\/code><\/td><td>Unquoted name in <code>define()<\/code><\/td><td>Add quotes: <code>define('SCRIPT_ROOT', ...)<\/code><\/td><\/tr><tr><td><code>Undefined constant \"Y\"<\/code><\/td><td>Unquoted string in <code>date()<\/code><\/td><td>Add quotes: <code>date('Y')<\/code><\/td><\/tr><tr><td><code>Undefined constant \"email\"<\/code><\/td><td>Unquoted array key<\/td><td>Add quotes: <code>$_SESSION['email']<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<h2 class=\"wp-block-heading\" id=\"two-ways-to-handle-this\">Two Ways to Handle This<\/h2>\n\n<h3 class=\"wp-block-heading\" id=\"option-1-roll-back-to-php-74-quick-fix\">Option 1: Roll Back to PHP 7.4 (Quick Fix)<\/h3>\n\n\n<p>If your site just broke and you need it live immediately, rolling back the PHP version is the fastest option. On cPanel with CloudLinux:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to <strong>cPanel<\/strong><\/li>\n\n\n\n<li>Go to <strong>MultiPHP Manager<\/strong><\/li>\n\n\n\n<li>Find your domain<\/li>\n\n\n\n<li>Select <strong>PHP 7.4<\/strong> from the dropdown<\/li>\n\n\n\n<li>Click <strong>Apply<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Your site will be back up within seconds. Keep in mind that PHP 7.4 is end-of-life and no longer receives security updates. This should be a temporary fix, not a permanent one.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"option-2-fix-the-code-proper-fix\">Option 2: Fix the Code (Proper Fix)<\/h3>\n\n\n<p>The right long-term solution is to update the code to be PHP 8 compatible. The fixes are small. It is mostly a matter of adding missing quotes in the right places.<\/p>\n\n\n\n<p>If you&#8217;re on shared hosting and have SSH or cPanel Terminal access, you can find all affected files quickly:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d88e02391b4847071d22693326e23716\"><code># Find unquoted date() calls\ngrep -rn \"date(Y\" \/home\/username\/public_html\/ --include=\"*.php\"\n\n# Find unquoted array keys with 'email'\ngrep -rn '\\&#091;email\\]' \/home\/username\/public_html\/ --include=\"*.php\"<\/code><\/pre>\n\n\n\n<p>Once you know which files are affected, you or your developer can fix them one by one.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"before-your-next-migration-a-short-checklist\">Before Your Next Migration, A Short Checklist<\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Take a full backup<\/strong> before any server or PHP version change<\/li>\n\n\n\n<li><strong>Test on a staging environment<\/strong> first if possible<\/li>\n\n\n\n<li><strong>Check your PHP error log<\/strong> immediately after migration to catch issues early<\/li>\n\n\n\n<li><strong>Scan your codebase<\/strong> for PHP 8 incompatibilities before upgrading tools like <a href=\"https:\/\/github.com\/PHPCompatibility\/PHPCompatibility\" target=\"_blank\" rel=\"noopener\">PHPCompatibility<\/a> can help<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"summary\">Summary<\/h2>\n\n\n<p>Things PHP 7 used to overlook silently, like unquoted constant names, unquoted array keys, and unquoted date format strings, now cause fatal errors. The fixes are straightforward, but they can be spread across many files, which is why sites often break after a migration without anyone expecting it.<\/p>\n\n\n\n<p>If you&#8217;re a client on our hosting and your site broke after a server migration, contact our support team. We can check your error logs and get it sorted.<\/p>\n\n\n\n<p><em>Published by Veeble Hosting \u00b7 Support Team KB<\/em><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP 8 introduced stricter syntax enforcement that silently breaks code written for PHP 7.4. Things the older interpreter accepted without complaint, like unquoted constant [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":9095,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[34,77,76,81,79,80,78],"class_list":["post-9092","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers-stuff","tag-cpanel","tag-php","tag-php-8","tag-php-errors","tag-server-migration","tag-shared-hosting","tag-wordpress"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/05\/php_upgrade_featured_article-scaled.jpg",2560,1354,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/05\/php_upgrade_featured_article-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/05\/php_upgrade_featured_article-300x159.jpg",300,159,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/05\/php_upgrade_featured_article-768x406.jpg",768,406,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/05\/php_upgrade_featured_article-1024x542.jpg",1024,542,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/05\/php_upgrade_featured_article-1536x812.jpg",1536,812,true],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/05\/php_upgrade_featured_article-2048x1083.jpg",2048,1083,true]},"uagb_author_info":{"display_name":"Nasarul Naseer","author_link":"https:\/\/www.veeble.com\/kb\/author\/nasarulnaseer\/"},"uagb_comment_info":0,"uagb_excerpt":"PHP 8 introduced stricter syntax enforcement that silently breaks code written for PHP 7.4. Things the older interpreter accepted without complaint, like unquoted constant [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/9092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=9092"}],"version-history":[{"count":7,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/9092\/revisions"}],"predecessor-version":[{"id":9100,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/9092\/revisions\/9100"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/9095"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=9092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=9092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=9092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}