# 类常量访问权限控制

现在起支持设置类常量的可见性。可使用private、protected、public权限控制．

```php
class ConstDemo
{
    // 常量默认为 public
    const PUBLIC_CONST_A = 1;

    // 可以自定义常量的可见范围
    public const PUBLIC_CONST_B = 2;
    protected const PROTECTED_CONST = 3;
    private const PRIVATE_CONST = 4;

    // 多个常量同时声明只能有一个属性
    private const FOO = 1, BAR = 2;
}

class ConstDemo1 extends ConstDemo
{
    public function __construct() {
        echo self::PUBLIC_CONST_A;
        echo self::PUBLIC_CONST_B;
        echo self::PROTECTED_CONST;
        echo self::PRIVATE_CONST;
    }
}

 new ConstDemo1();
```

结果：

```php
123
```

由此可见用法和之前的对象属性和对象方法的控制一样．

此外，接口（interface）中的常量只能是 `public`属性：

```php
<?php
interface ICache {
    public const PUBLIC = 0;
    const IMPLICIT_PUBLIC = 1;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://php7.shujuwajue.com/php-71x-xin-te-xing/xin-te-xing/lei-chang-liang-private-protected-public-quan-xian-kong-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
