I'm trying the addElement shorthand straight out of the documentation
[1] and getting a fatal error.
require_once 'Zend/Form.php';
$form = new Zend_Form;
$form->addElement('text', 'username', array(
'validators' => array(
'alnum',
array('regex', false, '/^[a-z]/i')
),
'required' => true,
'filters' => array('StringToLower'),
));
result: Fatal error: Cannot unset string offsets in
/var/www/html/_includes/Zend/Form/Element.php on line 991
PHP 5.1.6, Element.php is version 8983 2008-03-21 (a snapshot), but
1.5.0 had the same error.
The error is due to this code (line 989):
if (isset($options['messages'])) {
$messages = $options['messages'];
unset($options['messages']);
}
The problem is isset($options['messages']) returns true even though
$options is the string '/^[a-z]/i'. Inside isset(), PHP casts 'messages'
to an int, so it's the same as isset($options[0]), which is the
character '/'! Since the isset passes, unset fails because you can't
unset a character from a string.
My feeling is that isset should be fixed, but for the time being, a
Zend_Form_Element fix is simple:
if (is_array($options) && isset($options['messages'])) {
$messages = $options['messages'];
unset($options['messages']);
}
[1] http://framework.zend.com/manual/en/zend.form.quickstart.html
--
Steve Clay
http://mrclay.org/