Hi all,

I use quite a lot of decorators on form elements an I apply them at various
points at runtime, depending on how exactly the form should display,
depending on its state.

I get this warning (serveral times): 
Warning: substr_compare() [function.substr-compare]: The length cannot
exceed initial string length in
D:\ZendFramework\library\Zend\Form\Element.php on line 1553

Because it doesn't give much of a clue as to where in my code I went wrong,
or wether this is a bug, I decided to modify the code to give me more
information:

Warning: substr_compare() [function.substr-compare]: The length cannot
exceed initial string length in
D:\ZendFramework\library\Zend\Form\Element.php on line 1553
Decorator by name Label (div ) may have triggered the warning.

>From the code, it is now obvious that someone is trying to get a Label
decorator and while looping over the _decorators, one is found, named 'div',
that has fewer characters then 'Label' and thus triggers the error.

The code in Element.php:
    /**
     * Retrieve a registered decorator
     * 
     * @param  string $name 
     * @return false|Zend_Form_Decorator_Abstract
     */
    public function getDecorator($name)
    {
        if (!isset($this->_decorators[$name])) {
            $decorators = array_keys($this->_decorators);
            $len = strlen($name);
            foreach ($decorators as $decorator) {
                if (0 === substr_compare($decorator, $name, -$len, $len,
true)) {
                        
                    return $this->_decorators[$decorator];
                }else{
                                echo "Decorator by name $name ($decorator ) may 
have triggered
the warning.";
                }
            }
            return false;
        }

        return $this->_decorators[$name];
    }

The line in bold does this mysterious comparison, that is probably used for
its being binary safe. In my less educated opinion, it would do to say if
$decorator === $name or if 0===stricomp($decorator, $name).

Does anyone know why the code needs to substringcompare in this place?

For now, I will just rename my div decorator to divdecorator, which has a
lot more character than Label and I expect to be fine.

Regards,

Bart McLeod
-- 
View this message in context: 
http://www.nabble.com/Warning-when-using-a-lot-of-decorators-on-a-form-element-tp17861112p17861112.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to