Constants in PHP
Constants in PHP are defined with a keyword CONST.
Unlike variables constants don’t take up memory. Constants make code more understandable and more flexible.
Let me explain these two things:
Let’s use maximum speed as an example.
- A constant with a name of maximum speed is more descriptive than a number.
- If maximum speed is to be charged, it is needed to change it only in one place, where the constant is defined and not look through the code to find all of occurrences of maximum speed. It would be a bad thing, if all of occurrences of it got changed, but one did not.
Comments
Post a Comment