# ExpressionDependency

> ExpressionDependency represents a dependency based on the result of a PHP expression.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [caching](/docs/api/yii/caching/index.md) › ExpressionDependency

| class | `yii\caching\ExpressionDependency` |
| --- | --- |
| Extends | [`Dependency`](/docs/api/yii/caching/dependency/index.md) » [`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/caching/ExpressionDependency.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/caching/ExpressionDependency.php#L26) |

ExpressionDependency represents a dependency based on the result of a PHP expression.

ExpressionDependency will use `eval()` to evaluate the PHP expression.
The dependency is reported as unchanged if and only if the result of the expression is
the same as the one evaluated when storing the data to cache.

A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
please refer to the [php manual](https://www.php.net/manual/en/language.expressions.php).

For more details and usage information on Cache, see the [guide article on caching](/docs/guide/caching-overview/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-data"></span>[`$data`](/docs/api/yii/caching/dependency/index.md#property-data) | `mixed` | The dependency data that is saved in cache and later is compared with the latest dependency data. Default: `null`. | [`Dependency`](/docs/api/yii/caching/dependency/index.md) |
| [`$expression`](#property-expression) | `string` | The string representation of a PHP expression whose result is used to determine the dependency. Default: `'true'`. | `ExpressionDependency` |
| [`$params`](#property-params) | `mixed` | Custom parameters associated with this dependency. Default: `null`. | `ExpressionDependency` |
| <span id="property-reusable"></span>[`$reusable`](/docs/api/yii/caching/dependency/index.md#property-reusable) | `bool` | Whether this dependency is reusable or not. Default: `false`. | [`Dependency`](/docs/api/yii/caching/dependency/index.md) |

## 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) |
| <span id="method-evaluateDependency"></span>[`evaluateDependency()`](/docs/api/yii/caching/dependency/index.md#method-evaluateDependency) | Evaluates the dependency by generating and saving the data related with dependency. | [`Dependency`](/docs/api/yii/caching/dependency/index.md) |
| <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) |
| <span id="method-isChanged"></span>[`isChanged()`](/docs/api/yii/caching/dependency/index.md#method-isChanged) | Checks whether the dependency is changed. | [`Dependency`](/docs/api/yii/caching/dependency/index.md) |
| <span id="method-resetReusableData"></span>[`resetReusableData()`](/docs/api/yii/caching/dependency/index.md#method-resetReusableData) static | Resets all cached data for reusable dependencies. | [`Dependency`](/docs/api/yii/caching/dependency/index.md) |
| [`generateDependencyData()`](#method-generateDependencyData) protected | Generates the data needed to determine if dependency has been changed. | `ExpressionDependency` |
| <span id="method-generateReusableHash"></span>[`generateReusableHash()`](/docs/api/yii/caching/dependency/index.md#method-generateReusableHash) protected | Generates a unique hash that can be used for retrieving reusable dependency data. | [`Dependency`](/docs/api/yii/caching/dependency/index.md) |

## Property details

### $expression <span id="property-expression"></span>

```php
public string $expression = 'true'
```

The string representation of a PHP expression whose result is used to determine the dependency.

A PHP expression can be any PHP code that evaluates to a value. To learn more about what an expression is,
please refer to the [php manual](https://www.php.net/manual/en/language.expressions.php).

### $params <span id="property-params"></span>

```php
public mixed $params = null
```

Custom parameters associated with this dependency.

You may get the value
of this property in [`$expression`](/docs/api/yii/caching/expressiondependency/index.md#property-expression) using `$this->params`.

## Method details

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

```php
protected function generateDependencyData(yii\caching\CacheInterface $cache): mixed
```

Generates the data needed to determine if dependency has been changed.

This method returns the result of the PHP expression.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$cache` | [`CacheInterface`](/docs/api/yii/caching/cacheinterface/index.md) | The cache component that is currently evaluating this dependency |

**Returns**

`mixed`: The data needed to determine if dependency has been changed.