I don’t think I’ve ever had a case where I didn’t know if a constant had been set or not… seems a little against the principle of a constant
I’m also more likely to use a class constant than create it in the global scope these days.
I guess that makes sense. Depends on what extensions are loaded though.
EDIT: Downvotes? Why the hate, I’m just trying to have a discussion. Besides, I was agreeing with him.
That’s a good question that clearly demonstrates how much abuse a null coalescing operator is getting in the wild. Amateur programmers take it as a mere excuse for the laziness. And surely, taken from this point of view, the principle could be extended to constants – why not?
The problem is, isset(), empty() and null coalescing operators must be used warily and by no means as a mild version of the error suppressing operator. You need to understand that error messages are your friends, not foes. And error messages shouldn’t be gagged but rather allowed to tell you about inconsistencies in your code.
In most cases, accessing an undefined variable is a severe programming error
And that for a constant is tenfold.
Instead of routinely silencing it you have to make it vocal, to let it help you. Hence you need to fix the code, not the error message
pls no
Members
Online