deprecatedApi example

<?php /* We have not caught up on the deprecations yet and still call the other lib in a deprecated way. */

include __DIR__.'/../lib/SomeService.php';
$defraculator = new \acme\lib\SomeService();
$defraculator->deprecatedApi();

namespace App\Services;

use acme\lib\SomeService;
use foo\lib\SomeOtherService;

final class AppService
{
    public function directDeprecationsTwoVendors()
    {
        $service1 = new SomeService();
        $service1->deprecatedApi();

        $service2 = new SomeOtherService();
        $service2->deprecatedApi();
    }

    public function selfDeprecation(bool $useContracts = false)
    {
        $args = [__FUNCTION__, __FUNCTION__];
        if ($useContracts) {
            trigger_deprecation('App', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args));
        } else {
            @

        $args = [__FUNCTION__, __FUNCTION__];
        if ($useContracts) {
            trigger_deprecation('acme/lib', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args));
        } else {
            @trigger_error(sprintf('Since acme/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED);
        }
    }

    public function indirectDeprecatedApi(bool $useContracts = false)
    {
        (new AnotherService())->deprecatedApi($useContracts);
    }
}
Home | Imprint | This part of the site doesn't use cookies.