mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG removeRequiredField() should use array_splice() instead of unset()
Function unset() preserves numeric keys and method removeRequiredField() will give a PHP notice about nonexistent array key and loop won't iterate throughout all elements in array on second method call (and all subsequent). So it's better to use foreach loop and array_splice() function (it doesn't preserve numeric keys).
This commit is contained in:
parent
d5a1c3d99a
commit
6aba24b3e9
@ -112,9 +112,9 @@ class RequiredFields extends Validator {
|
||||
}
|
||||
|
||||
public function removeRequiredField($field) {
|
||||
for($i=0; $i<count($this->required); $i++) {
|
||||
if($field == $this->required[$i]) {
|
||||
unset($this->required[$i]);
|
||||
foreach ($this->required as $i => $required) {
|
||||
if ($field == $required) {
|
||||
array_splice($this->required, $i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user