ZF-1769: Zend_Validate_StringLength allows max to be lower than min...

Issue Type: Improvement Created: 2007-07-26T09:07:30.000+0000 Last Updated: 2008-03-21T16:25:34.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Travis Elkins (chidera) Assignee: Darby Felton (darby) Tags: - Zend_Validate

Related issues: Attachments:



I'm using Zend_Validate_StringLength and having a problem. I jumped into the code to see if something was going on in the class that would help explain what I was seeing. Although I haven't gotten to the bottom of that particular problem, while looking over the code I noticed that there is no check when min or max is set to see if min is set to a value higher than max or if max is set to a value lower than min.

While writing this, I did consider the possibilty that there may be value in having min higher than max, but I couldn't think of anything in particular.

I marked this as trivial because I don't think it will be bothering people. BUT, unless there's a good reason not to, it may be a good idea to throw an exception in such circumstances to alert the developer that they're (probably) not using the validator properly....perhaps yielding unexpected results. Or worse yet, perhaps they'll get false positives or false negatives.

I have not actually executed any test, but am pretty sure that the validation will always fail. Throwing an exception when min and max are "backward" may simply save the developer some time troubleshooting.

I hope that's not too confusing. Please feel free to let me know if you have any questions.



Posted by Travis Elkins (chidera) on 2007-07-26T09:55:40.000+0000


I just realized that my statement, "validation will always fail" is not correct. I think it will fail when min is higher than max and max is not null.


Posted by Darby Felton (darby) on 2007-07-26T10:22:27.000+0000

I agree that it makes most sense to throw an exception when:

  1. the max is set to something less than the min, or
  2. the min is set to something greater than the max (if one has been specified)

This is a slight break to backward compatibility, but I think it is good to make this change, for the reasons that Travis already mentioned.

Posted by Darby Felton (darby) on 2007-07-26T15:46:36.000+0000

Resolved for 1.1.0 with SVN r5860. Since it is a minor BC break, I don't request review for merging with 1.0.1, for which code freeze is tomorrow.

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.