Click to See Complete Forum and Search --> : Way to have certain fields ignored in compare
ninja9578
October 26th, 2010, 04:00 PM
I have two fields that are equal to each other, except for one field. Is there a way to get the comparison to ignore that field? It's an iterator pointer, the iterator position should not matter when comparing objects to each other.
PeejAvery
October 26th, 2010, 04:22 PM
I'm sorry, can you be more specific? Some code to help us understand what you are doing?
ninja9578
October 27th, 2010, 09:33 AM
class foo {
private $_mapping = array(1,2,3);
private $_position = 0;
public function rewind() {
$this -> _position = 0;
}
public function current() {
return $this -> _mapping[$this -> _position];
}
public function key() {
return $this -> _position;
}
public function next() {
++$this -> _position;
}
public function valid() {
return isset($this -> _mapping[$this -> _position]);
}
}
$test = new foo();
$test2 = new foo()
foreach($test as $i){}
echo '' . $test == $test2; //false because _position is in different places, but the actual content in the same
PeejAvery
October 27th, 2010, 10:54 AM
I'm sorry but without any explanation, this still isn't helping. Let me try to explain what isn't exactly understandable...
I have two fields that are equal to each other, except for one field.
Two equal minus one results in none equal. So what exactly are you comparing?
What do you mean by field? Are these <input> values passed to the server?
ninja9578
October 27th, 2010, 02:20 PM
The mapping members are exactly the same, the _position item is different, but does not affect the "value" of the object publicly. I want the $test == $test2 to be true.
I want it be be the equivalent of this
bool operator == (const foo & $bar){
return $bar -> _mapping == $this -> _mapping;
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.