DEV Community

Discussion on: How to deprecate a type in php

Collapse
 
lvo profile image
Laurent VOULLEMIER

Interesting post ! Sadly I don't think it is possible to trigger a deprecation in a straightforward way in the case you present. Furthermore I'm not sure this chunk of code will work in all cases:

<?php

if (!class_exists(ShinyNewFoo::class, false)) {
    @trigger_error(
        'LegacyFoo is deprecated!',
        E_USER_DEPRECATED
    );
}

If ShinyNewFoo is used in your user's code before LegacyFoo, I'm not sure that the deprecation will be triggered.

Collapse
 
greg0ire profile image
Grégoire Paris

You're correct, that's why I labelled this a best effort, it's really not ideal, but I'm afraid it's all we have.