On 5/11/07, Mariano Guadagnini <mariano@xxxxxxxxx> wrote:
Hy people, I have an existential doubt regarding php classes. I have been a php programmer for quite a long time, but never could figure out the clear difference between using this-> or self:: when calling member functions, wether they are private or public. I used them indistinctly and seemed to sort the same effects, although, when working with statics classes, self:: was the only way to access members. Well, that's all, any can put me some light on the matter? Thanks, -- Mariano Guadagnini UVCMS S.R.L www.uvcms.com
Well you are correct that self means you can access a property without instantiating the object. It is really useful for a class that returns singletons, concrete implementations, or even a registry class. Take a look at http://us2.php.net/manual/en/language.oop5.patterns.php on example 19.26. Private and protected properties are to keep people from using your interface in ways you do not want. You might want to look up visibility http://us.php.net/public. In my opinion it is better to stay away from static methods except for in the examples above (there are more) because it makes unit testing harder when code is littered with static calls that can't be swapped out with mock objects. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php