Conversation
- Emit deprecation notices pointing to the actual call site in user code - Allow to redirect deprecated class names to their replacements via class_alias() - Resolve call site by walking the backtrace past autoloader frames To be expanded.
|
At least horde/util has no hard dependencies on anything notable. I will check details later. |
ralflang
left a comment
There was a problem hiding this comment.
I agree with putting the helper here if you don't want a dedicated component for it.
I don't agree with log spamming library users for using a migration path we actively offer and still use in 25+ places though.
Do not use this on Horde_Array right now.
|
It feels like a way to for many cases where we have unused cone in Let's deprecate redundant code in Let's agree to never change existing methods except for one of these specific cases:
If anything needs to be changed in incompatible way (even if just method signature), let's do this:
If we do not do it this way, we will create issues. Note, this obviously does not apply to new classes. Once again, my main concern is existing duplicated and unused code (such as |
|
ArrayUtils isn't unused though. |
|
With |
1. Add DeprecationHelper utility class
The helper can be used to redirect to another class by replacing the old class file with these 2 lines:
Of course it would be nicer to have a single root helper class, so we could do this:
or
In addition to the actual redirecton it also calls
trigger_error(or, optionally,error_log) to output deprecation notice with exact location of the deprecated code. It relies on autoloader to load old class, so only the first occurrence gets reported (overhead is small).The debug mode output example in case of
trigger_error:[horde] PHP ERROR: The Horde_Array class is deprecated. Switch to Horde\Util\ArrayUtils (.../vendor/horde/util/lib/Horde/Variables.php:364)And in case of
error_log(if 3rd parameter isfalse):DEPRECATED: The Horde_Array class is deprecated. Switch to Horde\\Util\\ArrayUtils (.../vendor/horde/util/lib/Horde/Variables.php:364)TODO: It might be a good idea to adjust Horde's error handler to suppress backtrace output for
E_USER_DEPRECATEDcase (the helper already reports exact location).2. Deprecate Horde_Array class (redirect to PSR-4 implementation)
This provides a working example, but many other classes could be redirected the same way, provided their methods/parameters are 100% compatible.
TODO: Add more helper methods for other scenarios (e.g. emit custom message and pinpoint location of the caller) for deprecated method or method parameters.