PHP passing a class to another class and using a constant from it -
i'm trying use constant class i'm passing class, can't work out how call it. can point out i'm going wrong:
class { const test = 1; } class b { protected $c; function func($c) { $this->c = $c; echo $this->c::test; // doesn't work } } $a = new a(); $b = new b(); $b->func($a);
accessing constants on instances on properties syntactical ambiguity/incompatibility in php versions < 7. you're doing work fine in versions >= 7. works fine in versions:
function func($c) { echo $c::test; }
in php < 7, you'll have resort to:
$c = $this->c; $c::test;
wiki
Comments
Post a Comment