Back to Phpstan

classConstant.deprecatedTrait

website/errors/classConstant.deprecatedTrait.md

2.2.1670 B
Original Source

Code example

php
<?php declare(strict_types = 1);

/** @deprecated Use NewHelper instead */
trait OldHelper
{
	public const VERSION = '1.0';
}

echo OldHelper::VERSION;

Why is it reported?

This error is reported by the phpstan-deprecation-rules extension.

A class constant is accessed directly on a trait that has been marked as @deprecated. Deprecated traits are planned for removal in a future version, and code should not rely on their constants.

How to fix it

Access the constant from a non-deprecated source instead:

diff-php
-echo OldHelper::VERSION;
+echo NewHelper::VERSION;