final classes and const references to objects

php.internals

Cristiano Duarte

23 years ago
What a work in Zend2 !!! It is getting great, but about object constants in class definition? I need to do something like this: class EnumException extends Exception{ } final class Car { //private const _ferrari = 0; const _porsche = 1; const _corvette = 2; //private const _last_value = 2; //public const ferrari = new Car(_ferrari); const porsche = new Car(_porsche); const corvette = new Car(_corvette); private $value; protected function __construct($value) { if (($value < 0) || ($value > _last_value)) { throw new EnumException(); } $this->value = $value; } public function value() { return $this->value; } } Everything works fine, except the final keyword for the class and the const initialization with an object. I think final classes would be a good approach in assuring that a class will not be modified(inherited). Why can´t objects be assigned to constants ? Is there another way of doing this in Zend2 ? Thanx, Cristiano Duarte

Cristiano Duarte

23 years ago
Hello... Is anyone thinking about it ? "Cristiano Duarte" <cunha17@uol.com.br> escreveu na mensagem news:20030509171832.30305.qmail@pb1.pair.com...
> What a work in Zend2 !!! It is getting great, but about object constants
in
> class definition? > I need to do something like this: > > class EnumException extends Exception{ } > final class Car { > //private > const _ferrari = 0; > const _porsche = 1; > const _corvette = 2; > > //private > const _last_value = 2; > > //public > const ferrari = new Car(_ferrari); > const porsche = new Car(_porsche); > const corvette = new Car(_corvette); > > private $value; > > protected function __construct($value) { > if (($value < 0) || ($value > _last_value)) { > throw new EnumException(); > } > $this->value = $value; > } > public function value() { > return $this->value; > } > } > > Everything works fine, except the final keyword for the class and the
const
> initialization with an object. > > I think final classes would be a good approach in assuring that a class
will