1
I need to call the root directory of my project, only the root independent of where the script is.
Researching I found the $_SERVER['DOCUMENT_ROOT']
and as good practice I want to pass this to a constant within an object using const
.
<?php
class Test{
const DIROOT = $_SERVER['DOCUMENT_ROOT'];
}
However I get the following error:
"Fatal error: Constant Expression contains invalid Operations in /var/www/html/sys/php/test.php on line 3"
If I try to declare it with pure string const DIROOT = "/exemplo";
works. Why ?
But the function
define()
can only be inside methods on the object like__construct()
. Proceeding ?– ayelsew
Yes, but it makes no sense to call her inside the class. In this case it would be global.
– Woss
define() may be anywhere, but it is used for global constants.
– gmsantos