0

I'm building a plugin for Wordpress and need to define constants. I created some constants in my plugin base file which work just fine. e.g.:

if(!defined('SIMleague_pluginName')){
    define('SIMleague_pluginName', 'SIM League');
}

Now I'm trying to add more constants:

if(!defined('SIMleague_active')){
    define('SIMleague_active', 'activated');
}

I just keep getting these errors for every constant I define:

Warning: Use of undefined constant ....

I'm I missing something? I tried to add multiple constants. Even copied the first one and changed the constant name and value to make sure I made no typo's. But still no luck ...

As debug code I use:

    <br/><p><?php echo SIMleague_active ?></p>
    <br/><p><?php echo SIMleague_pluginName ?></p>

First One gives an error, the second line works just fine.

Can someone explain this behavior?

ADDED (full error message):

Warning: Use of undefined constant SIMleague_active - assumed 'SIMleague_active' (this will throw an Error in a future version of PHP) in /volume1/web/esportstest/wp-content/plugins/SIMleague/classes/SIMleague_Admin_Settings.php on line 65 Call Stack: 0.0001 409912 1. {main}() /volume1/web/esportstest/wp-admin/admin.php:0 0.3584 9152128 2. do_action() /volume1/web/esportstest/wp-admin/admin.php:254 0.3585 9152504 3. WP_Hook->do_action() /volume1/web/esportstest/wp-includes/plugin.php:478 0.3585 9152504 4. WP_Hook->apply_filters() /volume1/web/esportstest/wp-includes/class-wp-hook.php:311 0.3585 9153632 5. SIMleague_Admin::my_plugin_options() /volume1/web/esportstest/wp-includes/class-wp-hook.php:287 0.3586 9153632 6. SIMleague_Admin::renderBasePage() /volume1/web/esportstest/wp-content/plugins/SIMleague/classes/SIMleague_Admin.php:27 0.3586 9153696 7. SIMleague_Admin_Settings::renderSettings() /volume1/web/esportstest/wp-content/plugins/SIMleague/classes/SIMleague_Admin.php:59 SIMleague_active

Both constants are defined following eachother in SIMleague.php and used in SIMleague_Admin_Settings (SIMleague_Admin_Settings extends SIMleague_Admin class)

  • Maybe this answer gives you a way to solve your problem: https://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean – Alberto Marin Aug 02 '20 at 13:13
  • Thanks Alberto for the link. I don't think I can solve my issue with this information. It's information about array handling in PHP. This is not the same for constants. – GRAPHXstudio Aug 02 '20 at 13:30
  • Can you share the full warning message you get? – Alberto Marin Aug 02 '20 at 13:32
  • Aberto, updated the question with the full warning message. Strange thing is, for the constant SIMleague_pluginName I don't have this issue. No warning and does what's expected – GRAPHXstudio Aug 02 '20 at 13:51

1 Answers1

0

Just found the problem. When uploading the files to the test server, I uploaded all my classes with the new files, except the base class, SIMleague.php This file is 1 level up in the folder hierarchy and was not replaced by the updated file.

Once I figured that one out, all went as plannned ....

@Alberto, thanks for your answers!