I notice Yii use Self:: and Yii:: through out in the code.
I just wonder why not use $this rather than Self::?
And why not create a class variable instead of Yii::?
Thanks
I notice Yii use Self:: and Yii:: through out in the code.
I just wonder why not use $this rather than Self::?
And why not create a class variable instead of Yii::?
Thanks
Hi chanh,
this is how to use scope resolution … you’ll find all the details here : http://fr2.php.net/m…nekudotayim.php
hope this helps
So for the most part Self:: is the same as $this.
Yii:: is use without the need to do a New declaration.
Is that sound correct?
Thanks
self:: or ClassName:: is used to reference static member variables or methods, while $this the rest.
exactly.
Take a look the the php file located in yii-1.0.3.r780/framework (where you’ve installed yii framework) and open YiiBase.php. You’ll see that it is full of public static methods, so you don’t have to call new if you want to use these methods, just write Yii::methodName(…) and you’re done
self:: is used to get static variables.
yes, Yii:: is used without the need to do the New declaration.
Quote
And why not create a class variable instead of Yii::?
When it's Yii:: you can access it from anywhere, if you create an instance of it, you have to pass it around to have access to Yii class, which gets messy. Because of this we need to have static methods and static variables, ie. we need self:: to access them. As far as I remember it's also quicker to access/call static variables/methods than not static.
Ah, that is nice!
I guess that is reason to go PHP 5!
Thanks