Symfony service, tagged_locator works with the configuration in yaml but not in php

  dependency-injection, php, symfony, symfony5

I use the tagged_locator in my service configuration
Everything works with a yaml configuration.
But when I do the config in php, it doesn’t work anymore.
The parameter of my service is not filled
(0 providedServices)

Configuration Yaml

    # default configuration for services in *this* file
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
        resource: '../src/'
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
        resource: '../src/Controller/'
        tags: ['controller.service_arguments']

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

    # Will tag automatically all service that implement the VoterInterface created
                - ''

            - !tagged_locator ''

Configuration Php

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();


    $services->load('App', __DIR__.'/../src/')

    $services->load('AppController', __DIR__.'/../src/Controller/')



My service

$criteria contains list of services implementing Criterioninterface

class PostVoter extends Voter
    private $criteria;

    public function __construct(ServiceLocator $criteria)
        $this->criteria = $criteria;

    protected function supports(string $attribute, $subject)
        dump($this->criteria->getProvidedServices()); //empty array in php config

        return $subject instanceof Entry && $this->criteria->has($attribute);

dump($this->criteria->getProvidedServices());//empty array in php config

Example class used this interface

class CanEdit implements CriterionInterface
    public function handle(Entry $post, User $user): bool
        return $user === $post->getOwner();

Thank you for your helping

Source: Symfony Questions