![]() |
Hello
Hello to everybody. I saw that is a "tradition" that new members do here a very short presentation. So I start saying that my native language is not english so I apoligize for gramatical and exprimal mistakes.
I am relative new in php and I search for information in this domain. A problem that i have is with the OOP. I dont know how to use the "::" operator.I have some big books with php but neither one covers this operator. I saw in some joomla code that it's use without creating an object. The "->" is in every book. Thanks |
welcome aboard!
a simple explanation the :: operator addresses static methods or constant properties inside a class without the need to make an instance of the class |
Thanks. This is a problem that i search explanation for some time.
|
Ill try to explain quickly:
The use of :: is when you want to call a method of a class directly. You use -> on an object of a class. An object is een instance of a class (e.g. $obj = new ClassName();) this means that the object is a piece that inheritted all kinds of properties and methods from the class. The class is the blueprint for the object. When you want to access the method from the object, you use $obj->myMethod(). What myMethod does all depents how the blueprint (class) looks like. Now the :: operator removes the whole instance class, with it you can skip it all and access the method directly. The only downside is that your method wont be able to use the $this property. Calling a method via :: is called a static call. (In many other languages, you first have to declare your function static before you are able to call it on a static way) |
| All times are GMT. The time now is 07:51 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0