Recently, I started using CONSTANTS in my website, and so far they have been a welcome addition.
But now I am seeing one downside which I’ll describe in a minute…
In my “change-details.php” script, I have one constant called BIO_MAX which defines the number of characters Users can use to describe themselves…
if ($bioLength <= BIO_MAX){
// Valid Bio.
// Continue processing...
}else{
// Invalid Bio.
$errors['bio'] = "Your Bio cannot exceed " . BIO_MAX . " characters. "
. "Your answer is " . number_format($bioLength) . " characters.";
}
}
I was thinking of using this same coding style for the rest of my “User Profile” form, however, here is a “catch” that makes me wonder if Constants are such a good idea in a place like this after all…
In my database, I defined “user-bio” as VARCHAR(1024), so, if I only ever want to make this field smaller, then only having to update ONE CONSTANT is great.
However, the minute I forget about the Database, and accidentally give my long-winded Users 2,048 Characters - via BIO_MAX - to describe themselves, then all of that extra text will be lost?!
Some of you will say, “Well, Debbie, just don’t forget!!” To which I’d say, “Program so you don’t have to remember!”
My thinking is this…
Constants are great, but to assign a Field-Length Constant to every field in my “User Details” page might cause more headaches than just hard-coding field lengths.
There are Pros and Cons to each approach.
What do you think about the scenario I just described?
Sincerely,
Debbie