Cookie management in Yii

Comparing #3 with #4

Revision #4 was created by Rodrigo Coelho Rodrigo Coelho on Apr 20, 2011, 4:25:57 PM.

small typo correction

Content

[...]
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 examples in previous chapter). If you omit that, you'll get warning or error saying that object of class CHttpCookie cannot be converted to a string.

### Safe reading

On the same basis, as above, if a particular cookie does not exists, a corresponding object (CHttpCookie instance) for it will not be created! Trying to read such cookie will result in error "Trying to get property of non-object".
ItTo avoid that, it is always better to read a cookie using ternary operator, like that:


```php
$cookie = (isset(Yii::app()->request->cookies['cookie_name']->value)) ? Yii::app()->request->cookies['cookie_name']->value : '';
```
[...]