If it is in a class then do this public const GREATING = 'Hello World'; ClassName::GREATING
. But if it isn't then do this define("GREETING", "Hello World"); echo GREETING;
But to recreate what I think you want assuming you would like the setup fee
to be modifiable:
class Finance extends Model
{
// Am going to leave these yere for references...
public const DUE_DILIGENCE_FEE = 'Due Diligence Fee';
public const SETUP_FEE = 'Setup Fee';
public const REGISTRATION_FEE = 'Registration Fee';
protected $fee_const;
public function setFeeConst($fee)
{
$this->fee_const = $fee;
return $this;
}
public function getFeeConst()
{
return $this->fee_const;
}
}
class AchAgreementService
{
public function issue_fees($fee)
{
$finance = (new Finance)->setFeeConst($fee);
dd($finance->getFeeConst());
}
}
But if it's going to be constant then:
class Finance extends Model
{
public const DUE_DILIGENCE_FEE = 'Due Diligence Fee';
public const SETUP_FEE = 'Setup Fee';
public const REGISTRATION_FEE = 'Registration Fee';
// This is key...you cant call something you didn't set
public const FEE_CONST = 'Fee const';
}
class AchAgreementService
{
public function issue_fees($fee)
{
$fee_const = strtoupper($fee);
// Also pay attention to how am calling it without the dollar sign ($).
// This is going to work
dd(Finance::FEE_CONST);
// It is also important to note that you cant do this
// Finance::FEE_CONST = $fee;
}
}
If you're going to change the value of FEE CONST
then use the first approach.