ID: 23684 User updated by: cunha17 at uol dot com dot br Reported By: cunha17 at uol dot com dot br Status: Open Bug Type: Feature/Change Request Operating System: Linux -PHP Version: 5CVS-2003-05-18 (dev) +PHP Version: 5CVS-2003-07-28 (dev) New Comment:
>From CVS-2003-05-18 to CVS-2003-07-28: The final keyword was added to PHP5. The const keyword supports some basic expressions. I know that the const keyword is evaluated at compile time, is there another way to create a constant object? What I need to have is an object that is read only. Previous Comments: ------------------------------------------------------------------------ [2003-05-18 14:49:20] cunha17 at uol dot com dot br What a work in Zend2 !!! It is getting great, but what about final classes and 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 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23684&edit=1