Chris@0: name->parts) > 1) { Chris@0: $name = $this->getFullyQualifiedName($node->name); Chris@4: if (!\defined($name)) { Chris@4: $msg = \sprintf('Undefined constant %s', $name); Chris@0: throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); Chris@0: } Chris@0: } elseif ($node instanceof ClassConstFetch) { Chris@0: $this->validateClassConstFetchExpression($node); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Validate a class constant fetch expression. Chris@0: * Chris@0: * @throws FatalErrorException if a class constant is not defined Chris@0: * Chris@0: * @param ClassConstFetch $stmt Chris@0: */ Chris@0: protected function validateClassConstFetchExpression(ClassConstFetch $stmt) Chris@0: { Chris@0: // For PHP Parser 4.x Chris@0: $constName = $stmt->name instanceof Identifier ? $stmt->name->toString() : $stmt->name; Chris@0: Chris@0: // give the `class` pseudo-constant a pass Chris@0: if ($constName === 'class') { Chris@0: return; Chris@0: } Chris@0: Chris@0: // if class name is an expression, give it a pass for now Chris@0: if (!$stmt->class instanceof Expr) { Chris@0: $className = $this->getFullyQualifiedName($stmt->class); Chris@0: Chris@0: // if the class doesn't exist, don't throw an exception… it might be Chris@0: // defined in the same line it's used or something stupid like that. Chris@4: if (\class_exists($className) || \interface_exists($className)) { Chris@0: $refl = new \ReflectionClass($className); Chris@0: if (!$refl->hasConstant($constName)) { Chris@4: $constType = \class_exists($className) ? 'Class' : 'Interface'; Chris@4: $msg = \sprintf('%s constant \'%s::%s\' not found', $constType, $className, $constName); Chris@0: throw new FatalErrorException($msg, 0, E_ERROR, null, $stmt->getLine()); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: }