Hi,
I've learned php by myself and since some time ago I was focused only to version 4 cause I were woking on some projects that had to be php4 compatible.
Now this is over and I'm enjoying php5 and yii, but a couple of things about Classes and Objects are not 100% clear to me…
I know a bit OOP also thanks to java and was already working with classes also with php4… but for example just yesterday one question about the scope resolution operator camed in my mind…
Now from the documentation ( http://www.php.net/m…nekudotayim.php ) I thik to have the answer, but would like to share my thoughts with you so you can confirm this to me
If I've well understood, the meaning of this operator is to access to some methods and constants of an object without having to create an instance of it… works a bit like a singleton but you don't even have to assign it to a variable (=create the first instance and a pointer)
So… I tried to use “$this->anotherMethod()” inside a method I’ve called with MyClass::method() but I saw that it were trying to find it out as a method of my “parent” class… so I think in that case I had to use “self::anotherMethod()” … and that"$this->anotherMethod()" were the same of “parent::anotherMethod()” … am I right ? (maybe not: cause problably parent refers only to the constant / methods that are inherit from the parent class when you extend a class… )
I've also saw that if I creat an instance of the object, like:
$my_class =new MyClass();
and then I call "$my_class->method()" the "$this->anotherMethod()" call will look for a method named "anotherMethod" inside the $my_class object, as expected.
So… in which cases do you use the Scope Resolution Operator approach? And is it safe to rely on "$this" when you want your class to interact with the class that has called the static method of a class?
From the comment of “luka8088 at gmail dot com” it seems that if you use $this you get a strict warning…
thanks.
bye,
Giovanni.