Scopi
Scopi

Reputation: 673

Check if define variable is exist - warning error in php

Hi I have the following code and get the error even if i check if the variable is exist , why the php throw error? , how can I check it without error

 if(!defined (ENV)){
     define('ENV', getenv('ENV'));
 };

( ! ) Notice: Use of undefined constant ENV - assumed 'ENV' in  index.php on line 10

Upvotes: 0

Views: 262

Answers (1)

DB93
DB93

Reputation: 612

You forgot to use quotes with the defined function. It should look like this.

if(!defined ('ENV')){
    define('ENV', getenv('ENV'));
};

And when you want to output it you can use it without quotes.

echo ENV;

Upvotes: 1

Related Questions