-
October 27th, 2010, 09:44 AM
#1
What was the purpose of this design?
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;
}
}
-
October 27th, 2010, 07:54 PM
#2
Re: What was the purpose of this design?
If you want to refer to a member, then yes, you want to use $this. If you want to reference the class, then use self.
Not sure why the PHP council did it that way. You'll just have to ask them that.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 28th, 2010, 09:06 AM
#3
Re: What was the purpose of this design?
No, I mean, why is it possible for $this to be not of type self, or any inherited class of thereof?
-
October 28th, 2010, 10:09 AM
#4
Re: What was the purpose of this design?
Which is why I suggested you ask PHP.
http://bugs.php.net/report.php
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|