Constants defined programmatically trigger undefined constants warnings

I'm hoping for some suggestions to help with this problem.

In our project we setup alot of our constants programmatically depending on project and environment (dev vs deploy vs production), so we don't have classic define() calls for each constant.  Naturally PhpStorm believes all constants we use to be undefined, does anyone have any suggestions how we could give meta hints perhaps so that PhpStorm knows the constants are defined (which would also help with autocompletion of constants for us).

2 comments
Comment actions Permalink

You can just put an extra .php file anywhere in the project i.e.

/.meta/constants.php

and put fake constant definitions along with proper PHPDocs there i.e.

/**
* Use this constant to obtain DYNAMIC_ENV_SETTING value, wich is usually XXX for test env and YYY for production and is actually set via ZZZ mechanism.
*/
define("DYNAMIC_ENV_SETTING", "some_example_value");


This will make completion, type checking and doc work in IDE and is also a useful documentation.

1
Comment actions Permalink

This s a really good idea and works great, thanks!

0

Please sign in to leave a comment.