Ah, extra truthiness. Like how JavaScript had to add ===
Tue Sep 12, 2023 5:24pm

because == wasn't equal enough.

I think I found why it was evaluating to true if it wasn't defined in one of the comments in the PHP Manual:

Be aware that if "Notice"-level error reporting is turned off, then trying to use a constant
as a variable will result in it being interpreted as a string, if it has not been defined.

I was working on a program which included a config file which contained:

define('ENABLE_UPLOADS', true);

Since I wanted to remove the ability for uploads, I changed the file to read:

//define('ENABLE_UPLOADS', true);

However, to my surprise, the program was still allowing uploads. Digging deeper into the code, 
I discovered this:


Since 'ENABLE_UPLOADS' was not defined as a constant, PHP was interpreting its use as a string 
constant, which of course evaluates as True.

Yikes. haha

  • It's a PHP thing. If you define the symbol, you can use it - Puckdropper, Tue Sep 12 2023 3:08am
    elsewhere in your code. Kinda like a global, but not really a global. (And globals aren't. You have to explicitly tell your subroutine to use the global variable.) You'd think, and even a function checking for existence would tell you it didn't exist, but nothing really seemed to work. Perhaps... more
    • Ah, extra truthiness. Like how JavaScript had to add ===- Erik_, Tue Sep 12 2023 5:24pm
      • I think PHP has === too......... - Puckdropper, Fri Sep 15 2023 5:51am
        What really got me about the comment was everything before the comma: Be aware that if "Notice"-level error reporting is turned off, WHAT! The program behaves differently if a certain type of error reporting is enabled? I'd have never even thought about that as a possibility. The car pulls to... more
        • I didn't even catch that! - Erik_, Sat Sep 16 2023 10:17am
          That's crazy. It's like they took Perl's "use strict" and "use warnings" and combined them under just warnings for some reason.
"Forces act when not restrained" - Puckdropper