# Rule

> Rule represents a business constraint that may be associated with a role, permission or assignment.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [rbac](/docs/api/yii/rbac/index.md) › Rule

| abstract class | `yii\rbac\Rule` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/rbac/Rule.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/rbac/Rule.php#L21) |

Rule represents a business constraint that may be associated with a role, permission or assignment.

For more details and usage information on Rule, see the [guide article on security authorization](/docs/guide/security-authorization/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-createdAt"></span>`$createdAt` | `int` | UNIX timestamp representing the rule creation time Default: `null`. | `Rule` |
| <span id="property-name"></span>`$name` | `string` | Name of the rule Default: `null`. | `Rule` |
| <span id="property-updatedAt"></span>`$updatedAt` | `int` | UNIX timestamp representing the rule updating time Default: `null`. | `Rule` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`execute()`](#method-execute) abstract | Executes the rule. | `Rule` |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |

## Method details

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

```php
abstract public function execute(string|int $user, yii\rbac\Item $item, array $params): bool
```

Executes the rule.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$user` | `string\|int` | The user ID. This should be either an integer or a string representing the unique identifier of a user. See [`User::$id`](/docs/api/yii/web/user/index.md#property-id). |
| `$item` | [`Item`](/docs/api/yii/rbac/item/index.md) | The role or permission that this rule is associated with |
| `$params` | `array` | Parameters passed to [`CheckAccessInterface::checkAccess()`](/docs/api/yii/rbac/checkaccessinterface/index.md#method-checkAccess). |

**Returns**

`bool`: A value indicating whether the rule permits the auth item it is associated with.