# InvalidBehaviorAsDefinition

> Represents an as option of a Yii::createObject() configuration that yii\base\Component rejects, as found by yii2\extensions\phpstan\rules\BehaviorDefinitionResolver.

[API reference](/docs/api/index.md) › [PHPStan](/docs/extensions/phpstan/reference/index.md) › [rules](/docs/extensions/phpstan/reference/rules/index.md) › InvalidBehaviorAsDefinition

| final readonly class | `yii2\extensions\phpstan\rules\InvalidBehaviorAsDefinition` |
| --- | --- |
| Source | [`src/rules/InvalidBehaviorAsDefinition.php`](https://github.com/yii2-extensions/phpstan/blob/main/src/rules/InvalidBehaviorAsDefinition.php#L14) |

Represents an `as` option of a `Yii::createObject()` configuration that [`Component`](/docs/api/yii/base/component/index.md) rejects, as found by
[`BehaviorDefinitionResolver`](/docs/extensions/phpstan/reference/rules/behaviordefinitionresolver/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-calledClass"></span>`$calledClass` readonly constructor | `string` | Class through which `createObject()` is called, as PHPStan displays it. | `InvalidBehaviorAsDefinition` |
| <span id="property-definedClass"></span>`$definedClass` readonly constructor | `string\|null` | Class that the option names, or `null` for a configuration array without a class or a rejected value. | `InvalidBehaviorAsDefinition` |
| <span id="property-line"></span>`$line` readonly constructor | `int` | Line to report: the option key, or the call when the configuration doesn't locate it. | `InvalidBehaviorAsDefinition` |
| <span id="property-option"></span>`$option` readonly constructor | `string` | Option name as written, including the `as ` prefix. | `InvalidBehaviorAsDefinition` |
| <span id="property-owner"></span>`$owner` readonly constructor | `string` | Created component that receives the option, as PHPStan displays it. | `InvalidBehaviorAsDefinition` |
| <span id="property-resolvedClass"></span>`$resolvedClass` readonly constructor | `string\|null` | Class that the container resolves the named behavior class to, or `null` when `Component::__set()` rejects the option itself. | `InvalidBehaviorAsDefinition` |
| <span id="property-valueType"></span>`$valueType` readonly constructor | `string\|null` | Description of a rejected value that is no class name or configuration array, or `null` otherwise. | `InvalidBehaviorAsDefinition` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Stores a rejected `as` behavior definition and its diagnostic location. | `InvalidBehaviorAsDefinition` |
| [`message()`](#method-message) | Returns the diagnostic message, naming the call, the option, the owner and the defined and resolved classes. | `InvalidBehaviorAsDefinition` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $calledClass, string $owner, string $option, int $line, string|null $definedClass, string|null $resolvedClass, string|null $valueType)
```

Stores a rejected `as` behavior definition and its diagnostic location.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$calledClass` | `string` | Class through which `createObject()` is called, as PHPStan displays it. |
| `$owner` | `string` | Created component that receives the option, as PHPStan displays it. |
| `$option` | `string` | Option name as written, including the `as ` prefix. |
| `$line` | `int` | Line to report: the option key, or the call when the configuration doesn't locate it. |
| `$definedClass` | `string\|null` | Class that the option names, or `null` for a configuration array without a class or a rejected value. |
| `$resolvedClass` | `string\|null` | Class that the container resolves the named behavior class to, or `null` when `Component::__set()` rejects the option itself. |
| `$valueType` | `string\|null` | Description of a rejected value that is no class name or configuration array, or `null` otherwise. |

### message() <span id="method-message"></span>

```php
public function message(): string
```

Returns the diagnostic message, naming the call, the option, the owner and the defined and resolved classes.

**Returns**

`string`