PHP error guide

Use of undefined constant assumed string: meaning and fix

Error summary

Quote array keys; modern PHP throws Error for the same mistake. Older PHP treats an unknown bare identifier as a string while emitting a notice.

What it means

Quote array keys; modern PHP throws Error for the same mistake. Older PHP treats an unknown bare identifier as a string while emitting a notice.

What the error means

This message means that older PHP treats an unknown bare identifier as a string while emitting a notice. The exact signature distinguishes use of undefined constant assumed string from a generic application failure.

Why PHP produces it

The engine or service reports “Use of undefined constant assumed string” because its required precondition was not met. Quote array keys; modern PHP throws Error for the same mistake.

PHP version notes

The use of undefined constant assumed string wording here is based on PHP 5.x–7.4; fatal Error on PHP 8+; punctuation and exception class names can differ on older branches or vendor builds.

Most common causes

  • The immediate input or configuration reaches the specific condition: older PHP treats an unknown bare identifier as a string while emitting a notice
  • The code path assumes the prerequisite for use of undefined constant assumed string has already been satisfied.
  • For use of undefined constant assumed string, development and production differ in version, extension, permissions, paths, or service configuration.
  • An earlier operation returned an unchecked value that is consumed by the line reporting use of undefined constant assumed string.

Minimal examples

BAD — reproduces the problem

php
echo $row[status];

FIXED — safer pattern

php
echo $row["status"];

Step-by-step diagnosis

  1. Copy the complete “Notice: Use of undefined constant status - assumed 'status'” text and retain the first application stack frame.
  2. Reproduce use of undefined constant assumed string in the same SAPI and environment listed for this page.
  3. Before changing use of undefined constant assumed string, inspect the preceding value or directive and verify its type, path, version, and permissions.
  4. Apply the narrow correction—quote array keys; modern PHP throws Error for the same mistake—then repeat the original request once.

Fixes

Correct the failing prerequisite

Quote array keys; modern PHP throws Error for the same mistake

php
echo $row["status"];

Fail explicitly at the boundary

Validate the condition before the operation that emits use of undefined constant assumed string, and log a safe diagnostic without credentials or full production paths.

Common mistakes when fixing it

  • Suppressing use of undefined constant assumed string instead of correcting its upstream condition.
  • Testing use of undefined constant assumed string only with the CLI binary when the failing request runs under FPM or Apache.
  • Changing a global setting for use of undefined constant assumed string before confirming the site-specific effective configuration.

How to prevent it

  • Add a focused test that exercises the boundary responsible for use of undefined constant assumed string.
  • Keep runtime versions, extensions, configuration, and deploy artifacts affecting use of undefined constant assumed string reproducible.
  • Validate external data and service return values before they can trigger use of undefined constant assumed string.

Web server / environment notes

apache, fpm, shared-hosting. The failure occurs where older PHP treats an unknown bare identifier as a string while emitting a notice

Tags: apache,fpm,shared-hosting

Categories