symfony/deprecation-contracts
Provides the global trigger_deprecation() helper to emit standardized, silenced deprecation notices with package name and version. Works with custom error handlers (e.g., Symfony ErrorHandler) to catch and log deprecations in dev and production.
Install the package with composer require symfony/deprecation-contracts. Then, anywhere in your codebase where you’re deprecating functionality (e.g., a controller action, service method, or helper), call trigger_deprecation() with at least three arguments: the package name, the version when deprecation was introduced, and a descriptive message. For example:
trigger_deprecation('my/package', '4.0', 'The "%s" helper is deprecated. Use "%s" instead.', 'legacyHelper()', 'NewHelper::process()');
To see these deprecations, ensure your app uses Symfony’s ErrorHandler (e.g., via Symfony\Component\ErrorHandler\ErrorRenderer\PhpErrorRenderer) or a compatible custom error handler—otherwise, notices are silently suppressed.
trigger_deprecation() first in the legacy method, before executing its logic, to warn callers before they proceed.DeprecationTrait with helper methods like warnDeprecation($old, $new) to reduce duplication across multiple classes.ErrorHandler::enable() early; in production, route them to a dedicated log channel (e.g., deprecations.log) for monitoring usage volume and patterns.E_USER_DEPRECATED, trigger_deprecation() does nothing visible—even if code paths are hit. Always verify via test or log output.'next' or ' upcoming' breaks downstream semantic-versioning expectations—use exact release versions (e.g., '4.2.0').function trigger_deprecation() {} anywhere (even in a test bootstrap) globally silences all deprecations from this package. Avoid in shared utilities or libraries.if (!function_exists('trigger_deprecation')) {
function trigger_deprecation(string $package, string $version, string $message, ...$args): void {
$msg = sprintf('Since ' . $package . ' ' . $version . ': ' . $message, ...$args);
trigger_error($msg, E_USER_DEPRECATED);
}
}
function_exists() guard) and often no-op when unconditionally overridden—so no measurable performance impact even in hot paths.How can I help you explore Laravel packages today?