vendredi 10 juillet 2020

Execute code when annotated function or property is used in PHP

How would I add "functionality" to the @deprecated annotation so that I can execute code before or after (ideally both) execution of a function or when a deprecated property is accessed?

So I want to use the @deprecated annotation in PHP to do different things independent to the normal behaviour of the called function, so that developers who add the annotation to a deprecated function don't have to add the functionality to the function (e.g. logging details of the call).

In that way I think it's very usable as a developer and the IDE also recognizes the @deprecated annotation by default and suggests you not to use it.

I'm running PHP 7.3 if that's important.





Aucun commentaire:

Enregistrer un commentaire