Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Запрещаем переопределение переменной в PHP с помощью класса SplEnum
<?php
/**
* @link https://pecl.php.net/package/SPL_Types
* @link http://php.net/manual/ru/class.splenum.php
*/
class Month extends SplEnum
{
const __default = self::January;
const January = 1;
const February = 2;
const March = 3;
// ...
}
// Вернёт Month::January
$month = new Month;
// Бросит исключение UnexpectedValueException
$month = 'January';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.