PHP Class Constants - Public, Private or Protected?

前端 未结 4 933
余生分开走
余生分开走 2020-12-09 14:43

Am I correct in assuming that const properties are automatically public? Is there a way to make them private or protected?

Thanks in advance.

4条回答
  •  春和景丽
    2020-12-09 15:19

    As of php7.1, you can define your class constants with access modifiers (public, private or protected). Have a look at the following example:

    ';
            echo self::anthony_stark, '
    '; } } echo superheroes::kal_el, '
    '; superheroes::show_remaining();

    Credits: http://dwellupper.io/post/48/defining-class-constants-in-php

提交回复
热议问题