note 123742 added to reflectionclass.getconstants

From: 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

« previous php.notes (#210525) next »