Menu

Error Identifier: constant.defineValue

← Back to constant.*

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

// phpstan.neon:
// parameters:
//   dynamicConstantNames:
//     DATABASE_ENGINE: string|null

define('DATABASE_ENGINE', false);

Why is it reported? #

When a global constant is listed in the dynamicConstantNames configuration with an explicit type, PHPStan checks that values assigned via define() are compatible with that type. In the example above, DATABASE_ENGINE is configured to accept string|null, but false is being assigned.

This prevents the configured type from becoming inaccurate, which would lead to incorrect analysis results elsewhere in the codebase.

How to fix it #

Change the value to match the configured type:

-define('DATABASE_ENGINE', false);
+define('DATABASE_ENGINE', null);

Or update the configured type in phpstan.neon to accept the value:

 parameters:
 	dynamicConstantNames:
-		DATABASE_ENGINE: string|null
+		DATABASE_ENGINE: string|false|null

How to ignore this error #

You can use the identifier constant.defineValue to ignore this error using a comment:

// @phpstan-ignore constant.defineValue
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: constant.defineValue

Rules that report this error #

  • PHPStan\Rules\Constants\ValueAssignedToDefineRule [1]
Theme
A
© 2026 PHPStan s.r.o.