0

What is wrong with my code:

if(!defined(FILE_ROOT_PATH)){
    define('FILE_ROOT_PATH', $_SERVER['DOCUMENT_ROOT']);
}
echo 'Path: '.FILE_ROOT_PATH;

when run from CLI it gives:

Use of undefined constant FILE_ROOT_PATH - assumed 'FILE_ROOT_PATH' in ...

Can't I use constants on CLI?

3 Answers 3

2

You need to quote the string you pass to defined().

if(!defined('FILE_ROOT_PATH')){
    define('FILE_ROOT_PATH', $_SERVER['DOCUMENT_ROOT']);
}
echo 'Path: '.FILE_ROOT_PATH;

Otherwise, you're trying to reference the constant before it exists.

Sign up to request clarification or add additional context in comments.

Comments

1

This is wrong:

if(!defined(FILE_ROOT_PATH)){

defined() requires a string with the constant's name.

Comments

0
if(!defined('FILE_ROOT_PATH')){
define('FILE_ROOT_PATH', $_SERVER['DOCUMENT_ROOT']);
}
echo 'Path: '.FILE_ROOT_PATH;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.