Why Your Website Broke After a PHP Upgrade and How to Fix It

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.

How to Know If PHP Is the Cause

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’s your first clue.

Check your PHP error log from the site folder. If you see lines like these, PHP version is the cause:

These all point to the same type of issue: code that worked fine on PHP 7.4 but fails on PHP 8.

The Most Common Breaking Changes

Unquoted Constant Names in define()

This is probably the most common one. In PHP 7, you could write this, and it would work:

PHP 8 throws a fatal error because SCRIPT_ROOT is not a quoted string. It tries to find a constant called SCRIPT_ROOT before it has been defined.

The fix is simple, just add quotes around the constant name:

Same rule applies everywhere you use define(). The first argument must always be a quoted string.

2. Unquoted Array Keys

In PHP 7, using bare words as array keys was allowed:

PHP 8 treats email, username, and phone as constants, and since they are not defined, it throws a fatal error.

Always quote your array keys:

3. Unquoted Strings in date () Calls

This one shows up as Undefined constant "Y" in your error log. It happens when the date format string is passed without quotes:

Again, PHP 8 tries to look up Y as a constant and fails. The fix:

Quick Reference Table

Error in LogWhat It MeansFix
Undefined constant "SCRIPT_ROOT"Unquoted name in define()Add quotes: define('SCRIPT_ROOT', ...)
Undefined constant "Y"Unquoted string in date()Add quotes: date('Y')
Undefined constant "email"Unquoted array keyAdd quotes: $_SESSION['email']

Two Ways to Handle This

Option 1: Roll Back to PHP 7.4 (Quick Fix)

If your site just broke and you need it live immediately, rolling back the PHP version is the fastest option. On cPanel with CloudLinux:

  1. Log in to cPanel
  2. Go to MultiPHP Manager
  3. Find your domain
  4. Select PHP 7.4 from the dropdown
  5. Click Apply

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.

Option 2: Fix the Code (Proper Fix)

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.

If you’re on shared hosting and have SSH or cPanel Terminal access, you can find all affected files quickly:

Once you know which files are affected, you or your developer can fix them one by one.

Before Your Next Migration, A Short Checklist

  • Take a full backup before any server or PHP version change
  • Test on a staging environment first if possible
  • Check your PHP error log immediately after migration to catch issues early
  • Scan your codebase for PHP 8 incompatibilities before upgrading tools like PHPCompatibility can help

Summary

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.

If you’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.

Published by Veeble Hosting · Support Team KB

Scroll to Top