What are possibilities to implement helper that will raise error log with level E_DEPRECATED
(E_USER_DEPRECATED
in fact) when class method with annotation @deprecated
is called?
For example for the code
/**
* @deprecated
*/
public function main()
{}
when calling the method $obj->main()
the deprecated warning would be raised.
And yes, I know I could add a warning using code line trigger_error()
.
The @Deprecated annotation tells the compiler that a method, class, or field is deprecated and that it should generate a warning if someone tries to use it. That's what a deprecated class or method is.
If your functions are part of a class, then you could use trigger_error in the constructor to warn of the deprecation. Alternatively, if the functions are in a single file, then triggering a deprecation warning at the top of the file would show the error whenever the file is included elsewhere.
Annotation Types Used by the Java Language @Deprecated @Deprecated annotation indicates that the marked element is deprecated and should no longer be used. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation.
Similarly, when a class or method is deprecated, it means that the class or method is no longer considered important. It is so unimportant, in fact, that it should no longer be used at all, as it might well cease to exist in the future. The need for deprecation comes about because as a class evolves, its API changes.
In short: Put trigger_error()
at the beginning of the method.
Long: You need to reflect the class, retrieve the DocComment, parse it and extract the @deprecated
-tag. The problem is, that you must do this on every method call, and even if it there exists an easy way to catch every call, it would be a huge overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With