Closed weotch closed 2 years ago
@weotch Not the plugin maintainer but that's strange as I believe the CRAFT_ENVIRONMENT constant is still valid and works in Craft CMS 4.
https://craftcms.com/docs/4.x/config/#craft-environment
However, I do know by the default Craft CMS 4 now looks for environment variables with the CRAFT_ prefix against config settings now, what might be the issue is in the web/index.php, there was always this line present which defined CRAFT_ENVIRONMENT to a value.
https://github.com/craftcms/craft/blob/309136a5abb3ba48018caf10ea03b61fa4a4b744/bootstrap.php#L20
In Craft CMS 4 this has been removed due to Craft 4 automatically using environment variable names with the CRAFT_ prefix. So I assume this is why it's undefined.
Rather than getenv()
using the App helper with App::env('CRAFT_ENVIRONMENT')
is probably better though.
Without having to change the plugin you can fix this by defining the constant in your web/index.php and console file, but that's probably more of a workaround.
define('CRAFT_ENVIRONMENT', App::env('CRAFT_ENVIRONMENT') ?: 'dev');
@weotch & @jamesmacwhite thanks for point this out. I've fixed it more accordingly, i think, to Craft's way of doing this in Craft 4. Please let me know if this doesn't work as expected. See version: 2.0.0
@roelvanhintum Awesome, you can probably use ?:
when checking for presence of a CRAFT_ environment variable not present, so you can specify the fallback in a slightly cleaner way
I'm getting this error on PHP 8, Craft 4, and
2.0.0-beta.1
of this plugin: