In every other OOP language, you are guaranteed that 'this' is going to be of the type of class the code is in (minus if you do dumb typecasting of course.) Why on earth would PHP go against that? Are there any other places besides iterations where $this might not be valid?
Luckily the class I am wording with is a final one, so I can just check the name of the class type, but what if I were to use polymorphism?
Code:
public function valid() {
if (get_class($this) == 'subModuleList'){ //***? Goes against 30 years of OOP standards
echo 'good' . PHP_EOL;
$this -> _fetch();
return isset($this -> _mapping[$this -> _position]);
} else {
echo 'bad' . PHP_EOL;
return false;
}
}
Bookmarks