3 namespace PhpParser\Node\Stmt;
8 class Class_ extends ClassLike
10 const MODIFIER_PUBLIC = 1;
11 const MODIFIER_PROTECTED = 2;
12 const MODIFIER_PRIVATE = 4;
13 const MODIFIER_STATIC = 8;
14 const MODIFIER_ABSTRACT = 16;
15 const MODIFIER_FINAL = 32;
17 const VISIBILITY_MODIFIER_MASK = 7; // 1 | 2 | 4
19 const VISIBILITY_MODIFER_MASK = self::VISIBILITY_MODIFIER_MASK;
23 /** @var null|Node\Name Name of extended class */
25 /** @var Node\Name[] Names of implemented interfaces */
28 /** @deprecated Use $flags instead */
31 protected static $specialNames = array(
38 * Constructs a class node.
40 * @param string|null $name Name
41 * @param array $subNodes Array of the following optional subnodes:
42 * 'flags' => 0 : Flags
43 * 'extends' => null : Name of extended class
44 * 'implements' => array(): Names of implemented interfaces
45 * 'stmts' => array(): Statements
46 * @param array $attributes Additional attributes
48 public function __construct($name, array $subNodes = array(), array $attributes = array()) {
49 parent::__construct($attributes);
50 $this->flags = isset($subNodes['flags']) ? $subNodes['flags']
51 : (isset($subNodes['type']) ? $subNodes['type'] : 0);
52 $this->type = $this->flags;
54 $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null;
55 $this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array();
56 $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
59 public function getSubNodeNames() {
60 return array('flags', 'name', 'extends', 'implements', 'stmts');
63 public function isAbstract() {
64 return (bool) ($this->flags & self::MODIFIER_ABSTRACT);
67 public function isFinal() {
68 return (bool) ($this->flags & self::MODIFIER_FINAL);
71 public function isAnonymous() {
72 return null === $this->name;
78 public static function verifyModifier($a, $b) {
79 if ($a & self::VISIBILITY_MODIFIER_MASK && $b & self::VISIBILITY_MODIFIER_MASK) {
80 throw new Error('Multiple access type modifiers are not allowed');
83 if ($a & self::MODIFIER_ABSTRACT && $b & self::MODIFIER_ABSTRACT) {
84 throw new Error('Multiple abstract modifiers are not allowed');
87 if ($a & self::MODIFIER_STATIC && $b & self::MODIFIER_STATIC) {
88 throw new Error('Multiple static modifiers are not allowed');
91 if ($a & self::MODIFIER_FINAL && $b & self::MODIFIER_FINAL) {
92 throw new Error('Multiple final modifiers are not allowed');
95 if ($a & 48 && $b & 48) {
96 throw new Error('Cannot use the final modifier on an abstract class member');