note 123742 added to reflectionclass.getconstants
| From: | dmitrochenkooleg at gmail dot com | Date: | Fri, 05 Apr 2019 10:12:28 +0000 |
| Subject: | note 123742 added to reflectionclass.getconstants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210525@lists.php.net to get a copy of this message | ||
Get the latest constants declared.
abstract class AbstractEnum
{
/**
* ÐозвÑаÑÐ°ÐµÑ Ð²Ñе конÑÑанÑÑ
клаÑÑа || Return all constants
*
* @return array
*/
static function getConstants()
{
$rc = new \ReflectionClass(get_called_class());
return $rc->getConstants();
}
/**
* ÐозвÑаÑÐ°ÐµÑ Ð¼Ð°ÑÑив
конÑÑÐ°Ð½Ñ Ð¾Ð¿ÑеделеннÑе в
вÑзÑваемом клаÑÑе || Return last constants
*
* @return array
*/
static function lastConstants()
{
$parentConstants = static::getParentConstants();
$allConstants = static::getConstants();
return array_diff($allConstants, $parentConstants);
}
/**
* ÐозвÑаÑÐ°ÐµÑ Ð²Ñе конÑÑанÑÑ
ÑодиÑелÑÑкиÑ
клаÑÑов || Return parent
constants
*
* @return array
*/
static function getParentConstants()
{
$rc = new \ReflectionClass(get_parent_class(static::class));
$consts = $rc->getConstants();
return $consts;
}
}
======
class Roles extends AbstractEnum
{
const ROOT = 'root';
const ADMIN = 'admin';
const USER = 'user';
}
// Output:
All: root, admin, user
Last: root, admin, user
class NewRoles extends Roles
{
const CLIENT = 'client';
const MODERATOR = 'moderator';
const SUPERMODERATOR = 'super'.self::USER;
}
// Output:
All: client, moderator, superuser, root, admin, user
Last: client, moderator, superuser
class AdditionalRoles extends Roles
{
const VIEWER = 'viewer';
const CHECKER = 'checker';
const ROOT = 'rooter';
}
All: viewer, checker, rooter, client, moderator, superuser, admin, user
Last: viewer, checker, rooter
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 37.212.8.148)
----
Manual Page -- http://php.net/manual/en/reflectionclass.getconstants.php
Edit -- https://master.php.net/note/edit/123742
Del: integrated -- https://master.php.net/note/delete/123742/integrated
Del: useless -- https://master.php.net/note/delete/123742/useless
Del: bad code -- https://master.php.net/note/delete/123742/bad+code
Del: spam -- https://master.php.net/note/delete/123742/spam
Del: non-english -- https://master.php.net/note/delete/123742/non-english
Del: in docs -- https://master.php.net/note/delete/123742/in+docs
Del: other reasons-- https://master.php.net/note/delete/123742
Reject -- https://master.php.net/note/reject/123742
Search -- https://master.php.net/manage/user-notes.php