# InvalidBehaviorDefinition

> Represents a behavior definition that yii\base\Component can't attach, 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) › InvalidBehaviorDefinition

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

Represents a behavior definition that [`Component`](/docs/api/yii/base/component/index.md) can't attach, as found by [`BehaviorDefinitionResolver`](/docs/extensions/phpstan/reference/rules/behaviordefinitionresolver/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-definedClass"></span>`$definedClass` readonly constructor | `string\|null` | Class or container ID that the definition names, or `null` for a configuration array without a class. | `InvalidBehaviorDefinition` |
| <span id="property-line"></span>`$line` readonly constructor | `int` | Line to report: the list item, the definition argument or the return statement. | `InvalidBehaviorDefinition` |
| <span id="property-method"></span>`$method` readonly constructor | `string` | Method that supplies the definition: `behaviors`, `attachBehavior` or `attachBehaviors`. | `InvalidBehaviorDefinition` |
| <span id="property-name"></span>`$name` readonly constructor | `int\|string\|null` | Behavior name: a string for a named behavior, an `int` for an anonymous one, or `null` when the name isn't a single constant. | `InvalidBehaviorDefinition` |
| <span id="property-owner"></span>`$owner` readonly constructor | `string` | Class whose `behaviors()` returns the definition, or receiver type of the attach call, as PHPStan displays it. | `InvalidBehaviorDefinition` |
| <span id="property-resolvedClass"></span>`$resolvedClass` readonly constructor | `string\|null` | Class that the container resolves the defined class to, or `null` when the definition has no class. | `InvalidBehaviorDefinition` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Stores an unattachable behavior definition and its diagnostic location. | `InvalidBehaviorDefinition` |
| [`message()`](#method-message) | Returns the diagnostic message, naming the behavior, its owner and method, and the defined and resolved classes. | `InvalidBehaviorDefinition` |

## Method details

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

```php
public function __construct(string $owner, string $method, int|string|null $name, int $line, string|null $definedClass, string|null $resolvedClass)
```

Stores an unattachable behavior definition and its diagnostic location.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$owner` | `string` | Class whose `behaviors()` returns the definition, or receiver type of the attach call, as PHPStan displays it. |
| `$method` | `string` | Method that supplies the definition: `behaviors`, `attachBehavior` or `attachBehaviors`. |
| `$name` | `int\|string\|null` | Behavior name: a string for a named behavior, an `int` for an anonymous one, or `null` when the name isn't a single constant. |
| `$line` | `int` | Line to report: the list item, the definition argument or the return statement. |
| `$definedClass` | `string\|null` | Class or container ID that the definition names, or `null` for a configuration array without a class. |
| `$resolvedClass` | `string\|null` | Class that the container resolves the defined class to, or `null` when the definition has no class. |

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

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

Returns the diagnostic message, naming the behavior, its owner and method, and the defined and resolved classes.

**Returns**

`string`