I am trying to access a single data member of a class object using a constant. I was wondering if this is possible with syntax similar to what I use?
When I try to do this in the following script, I get this error: Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
class Certificate {
const BALANCE = 'cert_balance';
public function __construct() {}
}
class Ticket {
public $cert_balance = null;
public function __construct()
{
$this->cert_balance = 'not a chance';
echo $this->cert_balance."<br />";
}
}
$cert = new Certificate();
$ticket = new Ticket();
$ticket->$cert::BALANCE = 'nice!';
source
share