Re: final classes and const references to objects
| From: | Cristiano Duarte | Date: | Sun, 01 Jun 2003 20:29:01 +0000 |
| Subject: | Re: final classes and const references to objects | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-2122@lists.php.net to get a copy of this message | ||
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
> not be modified(inherited).
>
> Why can´t objects be assigned to constants ? Is there another way of doing
> this in Zend2 ?
>
> Thanx,
>
> Cristiano Duarte
>
>
>