With PHP we can define such variables whose values can not be changed after assigning. These varibles called CONSTANTS.
Constants are one type of variable which we can define for any class with keyword const. Value of these variables can not be changed any how after assigning.
Class constants are diffrent than normal variables, as we do not need $ to declare the class constants. Values for the class constants can not be mathematical operation, function call, variable or property. It can have constant expression.
We can use these constants in interface also. If you are not sure what is Interface then you can refer this article for Interface in PHP.
If we are inside the class then values of the constants can be get using self keyword, but accessing the value outside the class you have to use Scope Resolution Operator ::.
If you access constant using class object and Arrow Operator ->, you will end up with Notice of Undefined Property.
It will be better to use these Class Constants when you have variables with the fixed value, so It can not be changed further. Your suggestions?
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash