When using PHP5.3.1, if I pass a model to CHtml:encode e.g. CHtml::encode($model) and the model implements the __toString() method, then this is used to print the object. Yet when I deploy to PHP5.1.6 I get the following error
htmlspecialchars() expects parameter 1 to be string, object given
If I pass a normal attribute as e.g. CHtml::encode($model->attribute) then it works fine. However, if the model object happens to be null I will get the "trying to access property of non-object error. By simply passing the object to CHtml::encode it handled null relationships gracefully.
Whats the best way to handle model relationships which may be null when using CHtml::encode in a view?
amc.

Help













