Skip to content

Redefining constants leads to warning spam #5

Description

@lgommans
[Tue Jun 09 00:00:37.121924 2026] [php7:notice] [pid 1873272:tid 1873272] [client x:41356] PHP Notice:  Constant SPACEAPI_TEST_CONST already defined in /var/www/spaceAPI_config.php on line 3
[Tue Jun 09 00:00:37.124484 2026] [php7:notice] [pid 1873272:tid 1873272] [client x:41356] PHP Notice:  Constant SPACEAPI_KEY already defined in /var/www/spaceAPI_config.php on line 7

Caused by

include( $_SERVER['DOCUMENT_ROOT']."/../spaceAPI_config.php" );
and
include( $_SERVER['DOCUMENT_ROOT']."/../spaceAPI_config.php" );

I've hotfixed it by suppressing the warnings (see #6). Regarding a long-term fix:

  • Using include_once instead of include causes the database variables not to be set it seems (based on new warnings being shown; I didn't want to have it in a broken state so I quickly reverted that change)
  • PHP does not allow if ( not defined('X')) { const X = ...; } so we can't just wrap it in a check. We could use if ( not defined('X')) { define('X', ...); } maybe
  • Using define('X', ...); instead of const x = ...; behaves differently with scoping. We would need to check if that's a change we can do
  • We could migrate the global constants to variables, so having SPACEAPI_KEY be a $variable_name instead of a constant. Then redefinitions are not a problem.
  • Or vice versa: make them all global constants instead of variables, and we need not include it more than once.
  • The entries could be split out into separate files. Then we include the file with SPACEAPI_KEY once and the file with $variables wherever it is needed

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions