3
Notice: Use of undefined constant DOCUMENT_ROOT - assumed 'DOCUMENT_ROOT' in /home/syole/public_html/includes/config.php on line 21

Notice: Use of undefined constant DOCUMENT_ROOT - assumed 'DOCUMENT_ROOT' in /home/syole/public_html/includes/config.php on line 22

The PHP has seen an undefined constant which it is treating as the string, which has cause my website to display only a blank page, how do I make php understand that DOCUMENT_ROOT is predefined / should be predefined and is not a string?

I don't know where a " server configuration " might be but my website used to work and now it doesn't so I assume it must be defined correctly there, wherever that is, most likely on cpanel?

I think Coda2 caused this problem whilst connecting to my mySQL database.

I just cant seem to fix this issue and prior to adding error_reporting(E_ALL);, I didn't even know of this error.

HamZa
  • 14,671
  • 11
  • 54
  • 75
syole
  • 31
  • 1
  • 3
  • It's not a constant. It's not pre-defined. You need to quote it when accessing `$_SERVER['DOCUMENT_ROOT']`. – mario Mar 25 '13 at 01:01

3 Answers3

6

Don't do this:

$_SERVER[DOCUMENT_ROOT]

Do this instead:

$_SERVER['DOCUMENT_ROOT']

You need to quote strings (which this is), but not constants (which this isn't).

If you're using it inside an interpolated string, do it like this:

$a = "foo {$_SERVER['DOCUMENT_ROOT']} bar";

The {} braces allow you to use single/double quotes inside the double quoted string.

Cal
  • 7,067
  • 25
  • 28
  • Thank you, that has fixed this error. My website is still blank, which means my true error is something else, but this has really helped. – syole Mar 25 '13 at 01:14
2

Add this to your config file

 define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);

if you want to stick with your current constant call. Or you should do what @cal recommended.

0

XDebug indicates that 'DOCUMENT_ROOT' is a string, inside the Array() $_SERVER.

echo $_SERVER['DOCUMENT_ROOT'].'<br />';

echo gettype($_SERVER).'<br />';
echo gettype($_SERVER['DOCUMENT_ROOT']).'<br />';

echo '<pre>';
print_r($_SERVER);
echo '<pre>';