PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
public function equal($member, $value, $limit = 0)
{
$limitChk = 0;
if (self::_isMemberMethod($member)) {
for ($i=0; $i<$this->_size; $i++) {
if ($this->_array[$i]->$member() == $value) {
$this->_mask[$i] = $this->_state;
$limitChk++;
if ($limitChk == $limit) {
break;
}
}
}
} else {
for ($i=0; $i<$this->_size; $i++) {
if ($this->_array[$i]->$member == $value) {
$this->_mask[$i] = $this->_state;
$limitChk++;
if ($limitChk == $limit) {
break;
}
}
}
}
}
$member is a string that can be referring to either a method or a property. self::_isMemberMethod($method) returns true if it is a member and false otherwise. I need to perform the same loop either way but obviously one with () and one without, as you can see this is what I am doing.
The repetition of this is stark. I thought of using eval but I don't like that very much. Are there any suggestions as to how I should improve the repetition?
Not that I'm complaining or anything but I would just like to note that with '?' the truth evaluation of $method is repeated for every iteration of the loop.
Not that I'm complaining or anything but I would just like to note that with '?' the truth evaluation of $method is repeated for every iteration of the loop.
That's the price of removing second loop. Since the $method is Boolean, the price perhaps isn't high enough to consider.
Extremely argueable position. Eval is there for a reason, just like any other function in PHP. But it's being used in all the wrong ways possible though...