Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make PHP understand that DOCUMENT_ROOT is not a string? [duplicate]

Tags:

php

constants

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.

like image 287
syole Avatar asked Dec 30 '25 13:12

syole


1 Answers

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.

like image 64
Cal Avatar answered Jan 02 '26 03:01

Cal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!