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