**Note**: You should only use this if you are sure the cookie exists.
Also this may not work on PHP prior to 5.2 (See [PHP.net -> __toString()](http://www.php.net/manual/en/language.oop5.magic.php#object.tostring "PHP.net -> __toString()")).
See also "Safe reading" in the next chapter.
### Writing a cookie
There are multiple ways to write a cookie:
Since Yii 1.1.11 you don't have to specify the name of the cookie twice.
Notice, that you have to specify the name twice, if you want to use this:
```php
Yii::app()->request->cookies['cookie_name'] = new CHttpCookie('cookie_name', $value);
```
Notice, that cookie name must be given twice! See also "Reload required" in the next chapter.See also "Reload required" in the next chapter.
### Configure a cookie
Starting with Yii 1.1.11 you can configure an cookie upon creation.
The option parameter is internally passed to the public method [CHttpCookie::configure()](http://www.yiiframework.com/doc/api/1.1/CHttpCookie#configure-detail "CHttpCookie::configure()") which accepts an array with the following keys:
Cookies in Yii are read from [CHttpCookie](http://www.yiiframework.com/doc/api/1.1/CHttpCookie/ "") which is **an object**, that's why you have add **->value** to your code (see example. Also it is important to know that
```php
Yii::app()->request->cookies;
```
is ian previous chapter). If you omit that, you'll get warning or error saying that object of class CHttpCookie cannot be converted to a string.instance of [CCookieCollection](http://http://www.yiiframework.com/doc/api/1.1/CCookieCollection "CCookieCollection") which extends [CMap](http://www.yiiframework.com/doc/api/1.1/CMap "CMap"), therefore it is possible to use simliar to an array.