src/Helpers/Request/HtmlHelper.php
public function error($model, $attribute, $options = [], $encoding = null)
    {
        return $this->proxyWithCharset(__FUNCTION__, [$model, $attribute, $options, $encoding]);
    }
public function error($model, $attribute, $options = [], $encoding = null)
    {
        return $this->proxyWithCharset(__FUNCTION__, [$model, $attribute, $options, $encoding]);
    }
Generates a tag that contains the first validation error of the specified model attribute.
Note that even if there is no validation error, this method will still return an empty error tag.
@param Model  $model the model object
@param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
about attribute expression.
@param array  $options the tag options in terms of name-value pairs. The values will be HTML-encoded
using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.

The following options are specially handled:

- tag: this specifies the tag name. If not set, "div" will be used.
See also [[tag()]].
- encode: boolean, if set to false then the error message won't be encoded.
- errorSource (since 2.0.14): \Closure|callable, callback that will be called to obtain an error message.
The signature of the callback must be: `function ($model, $attribute)` and return a string.
When not set, the `$model->getFirstError()` method will be called.

See [[renderTagAttributes()]] for details on how attributes are being rendered.

@param string $encoding
@return string the generated label tag
@see Html::error()