Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SplEnum 为何不直接定义为:final class SplEnum,而在其内个方法添加final ???? #16

Open
twomiao opened this issue Jun 13, 2020 · 0 comments

Comments

@twomiao
Copy link

twomiao commented Jun 13, 2020

疑问:这样就可以删除方法上面“多余的final”,还是仅仅某些方法打算继承,才这样写???????
`final class SplEnum
{
private $val = null;
private $name = null;

public function __construct($val)
{
    $list = self::getConstants();
    //禁止重复值
    if (count($list) != count(array_unique($list))) {
        $class = static::class;
        throw new \Exception("class : {$class} define duplicate value");
    }
    $this->val = $val;
    $this->name = self::isValidValue($val);
    if($this->name === false){
        throw new \Exception("invalid value");
    }
}

public function getName():string
{
    return $this->name;
}

public function getValue()
{
    return $this->val;
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant