Skip to content

Commit

Permalink
BUG removeRequiredField() should use array_splice() instead of unset()
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
elvinas-liut committed Dec 18, 2012
1 parent d5a1c3d commit 6aba24b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions forms/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public function addRequiredField( $field ) {
}

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);
}
}
}
Expand Down

0 comments on commit 6aba24b

Please sign in to comment.