ZF-12172: formSelect Helper will not properly call __toString if object is passed as value

Issue Type: Bug Created: 2012-04-25T16:12:20.000+0000 Last Updated: 2012-04-25T16:12:20.000+0000 Status: Open Fix version(s): Reporter: Chuck Reeves (creeves1982) Assignee: Chuck Reeves (creeves1982) Tags: - Zend_Form

  • Zend_View

Related issues: Attachments:


When passing an object to Zend_View_Helper_FormSelect, the __toString method will not be called since the value is cast to an array in with array_map('strval', (array) $value);

This causes PHP error if some properties of the object do not implement __toString

Test Case

<pre class="highlight">
class Foo
    public $_filter;

    public $_value;

    public function __construct()
        $this->_filter = new Zend_Filter();

    public function setValue($value)
        $this->_value = $this->_filter->filter($value);
        return $this;

    public function __toString()
        return $this->_value;

$foo = new Foo();

echo $view->formSelect('test',

The above will throw a fatal error that Zend_Filter cannot be converted to string. I have a fix that I will apply to Zend_View_Helper_FormSelect:

<pre class="highlight">

if (is_object($value)) {
    //if the object can be iterated, loop through
    if ($value instanceof Iterator) {
    $temp = array();
    foreach($value as $key => $value) {
        $temp[$key] = (string) $value;

    $value = $temp;
    } else {
    $value = array((string) $value);
} else {
    $value = array_map('strval', (array) $value);


No comments to display

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.