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