In PHP, Why do I need to define case sensitive in a constant? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In PHP, Why do I need to define case sensitive in a constant?

it is a constant it wont change. I dont understand the concept or the use of it. Somebody can help me?

11th Jan 2019, 2:02 PM
Jorge Cueva
Jorge Cueva - avatar
7 Answers
+ 3
Variables are "flexible" values that can be changed, for example sum = 5+4 (sum equals 9), sum += 10 (sum equals 19) etc. Constants are values that can't be changed, for example PI = 3.1416 (π is always a fixed value and doesn't need to be changed). In most languages, it is good practice to begin names of constants with a capital letter (Pi) or to capitalize the whole name (PI). In some languages (I think for example in Ruby), it is automatically assumed that an object whose name starts with a capital letter is a constant and its value can't be changed after its initialization.
11th Jan 2019, 2:47 PM
Anna
Anna - avatar
+ 1
Thanks for Your answear but the question remains, why do I have to specify true or false for case sensitive
11th Jan 2019, 3:10 PM
Jorge Cueva
Jorge Cueva - avatar
+ 1
Jorge Cueva Uh, let's start with the question what programming language you're talking about. Do you have an example of where you're asked to specify true or false?
11th Jan 2019, 3:13 PM
Anna
Anna - avatar
+ 1
PHP
11th Jan 2019, 3:20 PM
Jorge Cueva
Jorge Cueva - avatar
+ 1
<?php define("MSG", " Hi SoloLearners!", true); echo msg; // Outputs "Hi SoloLearners!" ?> by default comes with case-insensitive
11th Jan 2019, 5:38 PM
Jorge Cueva
Jorge Cueva - avatar
+ 1
this us the function define(name, value, case-insensitive)
11th Jan 2019, 5:39 PM
Jorge Cueva
Jorge Cueva - avatar
+ 1
I already understood, by default it is "false" so it is - and - = + means that it will be case sensitive. So if you put the name of your constant all in capital letters for example, and send to call the constant in lowercase letters does not work
18th Jan 2019, 1:49 PM
Jorge Cueva
Jorge Cueva - avatar