php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23684 Final Classes and Const references to Objects
Submitted: 2003-05-18 14:49 UTC Modified: 2003-07-30 13:20 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cunha17 at uol dot com dot br Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5CVS-2003-07-28 (dev) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cunha17 at uol dot com dot br
New email:
PHP Version: OS:

 

 [2003-05-18 14:49 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-29 20:13 UTC] cunha17 at uol dot com dot br
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.
 [2003-07-30 13:20 UTC] helly@php.net
The current engine design doesn't allow this from PHP Code. However you could create your own object handlers to accomplish that in C level.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC