ZF-11855: Zend_Filter_PregReplace does not have a valid MatchPattern set (Array of matches)

Issue Type: Bug Created: 2011-10-27T20:00:46.000+0000 Last Updated: 2011-10-27T20:36:02.000+0000 Status: Open Fix version(s): Reporter: Glauco Lins (gateon) Assignee: Thomas Weidner (thomas) Tags: -

Related issues: Attachments:


When PregReplace filter is applied to a Zend_Form_Element_* it presents a strange behavior during match and replace.

Zend_Filter_PregReplace basically resumes itself to apply a "preg_replace()" on line 171 as shown below.

<pre class="literal">
preg_replace($this->_matchPattern, $this->_replacement, $value);

preg_replace allows the use of arrays for the MATCH and REPLACEMENT variables.

When performing the following code, an excepetion is thrown during validation. Message: Zend_Filter_PregReplace does not have a valid MatchPattern set.

<pre class="highlight">
class Application_Form_Example extends Zend_Form {

  public function init()
    $price = new Zend_Form_Element_Text('price');
    $price->addFilter('PregReplace', array(
             'match' => array('|,|', '|[^0-9\.]|'), 
             'replace' => array('.', '')

    $this->addElement(new Zend_Form_Element_Submit('submit'));

The test case itself might not be the best approach to format a 'price', but it ilustrate the problem. For the input string abc123,456.789 the expected output should be 123456.789.



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.