1# Attribute 2 3- `v::attribute(string $name)` 4- `v::attribute(string $name, v $validator)` 5- `v::attribute(string $name, v $validator, boolean $mandatory = true)` 6 7Validates an object attribute. 8 9```php 10$obj = new stdClass; 11$obj->foo = 'bar'; 12 13v::attribute('foo')->validate($obj); // true 14``` 15 16You can also validate the attribute itself: 17 18```php 19v::attribute('foo', v::equals('bar'))->validate($obj); // true 20``` 21 22Third parameter makes the attribute presence optional: 23 24```php 25v::attribute('lorem', v::stringType(), false)->validate($obj); // true 26``` 27 28The name of this validator is automatically set to the attribute name. 29 30*** 31See also: 32 33 * [Key](Key.md) 34