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.

  1. A constant with a name of maximum speed is more descriptive than a number.
  2. 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

Popular posts from this blog

Absolute and relative path in HTML pages

Errors

goto PHP operator