Version

Documentation » Admin

« 18. Preview Mode

19. Troubleshooting

19.1. The toString method

Sometimes the bundle needs to display your model objects, in order to do it, objects are converted to string by using the __toString magic method. Take care to never return anything else than a string in this method. For example, if your method looks like that :

public function __toString()
{
    return $this->getTitle();
}

You can’t be sure your object will always have a title when the bundle will want to convert it to a string. So in order to avoid any fatal error, you must return an empty string (or anything you prefer) for when the title is missing, like this :

public function __toString()
{
    return $this->getTitle() ?: '';
}

Found a typo? Something is wrong in this documentation? Just fork and edit it!