Can you undefine or change a constant in PHP?

后端 未结 6 1553
猫巷女王i
猫巷女王i 2020-12-16 09:18

Can you undefine or change a constant in PHP?

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 09:59

    I know this is late to the game... but here is one thing that might help some people...

    In my "Application.php" file (where I define all my constants and include in all my scripts) I do something like this:

    if( !defined( "LOGGER_ENABLED" )){
    define( "LOGGER_ENABLED", true );
    }
    

    So normally, every script is going to get logging enabled... but if in ONE particular script I don't want this behavior I can simply do this BEFORE I include my Application.php:

    define( "LOGGER_ENABLED", false );
    

提交回复
热议问题