Is a global PHP CONSTANT available inside of a Class file?
define('SITE_PATH', 'C:/webserver/htdocs/somefolder/');
Then in my class file I try this
public $debug_file = SITE_PATH. 'debug/debug.sql';
This does not seem to work though,
Parse error: parse error, expecting
','' or
';'' in C:\webserver\htdocs\somefolder\includes\classes\Database.class.php on line 21
I second what the others said. Since $debugFile seems an optional dependency, I'd suggest to initialize a sane default on creation of the class and then allow changing it by setter injection when needed, e.g.
define('SITE_PATH', 'C:/webserver/htdocs/somefolder/');
class Klass
{
protected $_debugFile;
public function __construct()
{
$this->_debugFile = SITE_PATH. 'debug/debug.sql' // default
}
public function setDebugFile($path)
{
$this->_debugFile = $path // custom
}
}
Note that injecting SITE_PATH, instead of hardcoding it, would be even better practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With