From: Robert Klemme Date: 2009-06-23T05:45:06+09:00 Subject: Re: Some confusion on self and the like.... On 22.06.2009 22:25, Alexander Trauzzi wrote: > Robert Klemme wrote: >> On 22.06.2009 21:22, Alexander Trauzzi wrote: >> >>> It was recently implemented in PHP as "late static binding" (as "self" >>> references the class in which it is used, as opposed to the context >>> during the invocation itself). >> Did you mean "defined" instead of "used"? Otherwise I cannot make much >> sense of what you write. >> >>> From what I'm reading here, "ruby does it right"(tm?) >> Yes - of course! :-) >> >>> Thanks for all your help guys, I will follow up in a new topic if I have >>> any further questions. >> You're very welcome. >> >> Kind regards >> >> robert > > Just to clarify: > > Simple example (language agnostic): > > o Class Animal > - Method eat() > o Class Cat Extends Animal > > > In PHP, what would happen is if you used "self" in Animal.eat, it would > always resolve the class to be Animal (which is just silly). PHP seemed > to look up against the source file, rather than the inheritance tree. > Then, in a recent release, they introduced late static binding and a > smattering of functions and keywords for it, which opened up the > opportunities for classes to reflect on themselves after being extended. PHP really seems to use "self" for the class and "this" for instances: http://de3.php.net/manual/en/language.oop5.constants.php > Its still not perfect, and I can see that Ruby has made more progress in > the realm of good OO behaviour. Ruby was OO from the start on - OO in Perl and PHP were retrofitted. > Hopefully that helps, just from an academic standpoint ;) Oh, IMHO this is not just academic. These are important things to know about a programming language. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/