Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Definition.php

function Definition::replaceArgument

Replaces a specific argument.

Return value

$this

Throws

OutOfBoundsException When the replaced argument does not exist

1 method overrides Definition::replaceArgument()
ChildDefinition::replaceArgument in vendor/symfony/dependency-injection/ChildDefinition.php
You should always use this method when overwriting existing arguments of the parent definition.

File

vendor/symfony/dependency-injection/Definition.php, line 252

Class

Definition
Definition represents a service definition.

Namespace

Symfony\Component\DependencyInjection

Code

public function replaceArgument(int|string $index, mixed $argument) : static {
    if (0 === \count($this->arguments)) {
        throw new OutOfBoundsException(\sprintf('Cannot replace arguments for class "%s" if none have been configured yet.', $this->class));
    }
    if (!\array_key_exists($index, $this->arguments)) {
        throw new OutOfBoundsException(\sprintf('The argument "%s" doesn\'t exist in class "%s".', $index, $this->class));
    }
    $this->arguments[$index] = $argument;
    return $this;
}
RSS feed
Powered by Drupal