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.
Pros:
function_exists() guards) and minimal footprint when active. Ideal for libraries/frameworks where deprecation consistency is critical.Deprecates trait in Symfony components) or custom error handlers (e.g., Sentry, Monolog).Cons:
Laravel-Specific:
symfony/error-handler package (or whoops) can intercept E_USER_DEPRECATED notices. Example:
use Symfony\Component\ErrorHandler\ErrorHandler;
ErrorHandler::register(); // Captures deprecations in all environments
ErrorHandler::setErrorRenderer(new MonologErrorRenderer(new Logger('deprecations')));
Migration Path:
symfony/deprecation-contracts and configure ErrorHandler to log deprecations to storage/logs/deprecations.log.Compatibility:
E_USER_DEPRECATED (PHP 8.1+). Laravel 9+ supports this natively.Deprecates trait (e.g., in Symfony bundles) or Laravel’s Deprecates facade (if available).Critical Gaps:
"next") break semantic expectations. Requires discipline in teams.Mitigation Strategies:
trigger_deprecation() in if (app()->bound('deprecation.enabled')) for feature flags.DeprecationTestCase to assert notices are triggered in CI:
public function testDeprecationIsTriggered() {
$this->expectDeprecation('my/package', '1.0', 'Old method is deprecated');
oldMethod();
}
trigger_error(E_USER_DEPRECATED, ...).Key Questions for TPM:
whoops).| Step | Action | Laravel-Specific Tooling |
|---|---|---|
| 1. Discovery | Audit legacy code for deprecated paths (e.g., via static analysis). | phpstan, psalm, or custom regex searches. |
| 2. Setup | Install package and configure ErrorHandler. | composer require symfony/error-handler + ErrorHandler::register(). |
| 3. Pilot | Tag 3–5 critical deprecations in a feature branch. | Use trigger_deprecation() in legacy methods. |
| 4. Monitor | Validate notices appear in logs/monitoring. | Check storage/logs/deprecations.log or Sentry. |
| 5. Scale | Roll out to all services; integrate with CI/CD. | Add DeprecationThreshold to GitHub Actions. |
| 6. Deprecate | Remove deprecated code after usage drops below a threshold (e.g., <1%). | Use deprecation_usage metrics from logs. |
E_USER_DEPRECATED.E_USER_DEPRECATED.symfony/error-handler).Whoops\Handler\PlainTextHandler.Symfony\Component\ErrorHandler\ErrorRendererInterface.php -d error_reporting=E_USER_DEPRECATED in test jobs.error_reporting in .gitlab-ci.yml.deprecations.log weekly (e.g., via Slack alerts).# Example: Find deprecations with zero usage in the last 30 days
grep "Since my/package" storage/logs/deprecations.log | awk '{print $NF}' | sort | uniq -c | grep -v "[0-9]"
X instead of Y."/legacy."DeprecationDebugger facade to list active deprecations in Tinker:
DeprecationDebugger::listActive(); // Returns array of triggered deprecations
How can I help you explore Laravel packages today?