I have defined a variable in a separate config file:
define('URL', 'someurl.co.uk');
However, when I try to use it to concat with a string inside a class:
class AdminEmail extends Email {
private $from = "jsmith".URL;
I get the following error:
Parse error: parse error, expecting `','' or `';''
But if I echo it out, it displays perfectly!
Hope I haven't missed anything obvious here!
You can't use constants, functions or other variables when pre-defining class variables. Class definitions are like blueprints, they must be completely independent from anything else going on in the script (except for dependencies on other classes of course.)
You would have to set this later, e.g. in the constructor:
class AdminEmail extends Email {
private $from;
function __construct()
{
$this->from = "jsmith".URL;
}
or in a separate function:
function setFrom($from)
{
$this->from = $from;
}