Chris@0: conditionalScopes++; Chris@0: } elseif ($node instanceof Function_) { Chris@0: $name = $this->getFullyQualifiedName($node->name); Chris@0: Chris@0: // @todo add an "else" here which adds a runtime check for instances where we can't tell Chris@0: // whether a function is being redefined by static analysis alone. Chris@0: if ($this->conditionalScopes === 0) { Chris@0: if (function_exists($name) || Chris@0: isset($this->currentScope[strtolower($name)])) { Chris@0: $msg = sprintf('Cannot redeclare %s()', $name); Chris@0: throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); Chris@0: } Chris@0: } Chris@0: Chris@0: $this->currentScope[strtolower($name)] = true; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Validate that function calls will succeed. Chris@0: * Chris@0: * @throws FatalErrorException if a function is redefined Chris@0: * @throws FatalErrorException if the function name is a string (not an expression) and is not defined Chris@0: * Chris@0: * @param Node $node Chris@0: */ Chris@0: public function leaveNode(Node $node) Chris@0: { Chris@0: if (self::isConditional($node)) { Chris@0: $this->conditionalScopes--; Chris@0: } elseif ($node instanceof FuncCall) { Chris@0: // if function name is an expression or a variable, give it a pass for now. Chris@0: $name = $node->name; Chris@0: if (!$name instanceof Expr && !$name instanceof Variable) { Chris@0: $shortName = implode('\\', $name->parts); Chris@0: $fullName = $this->getFullyQualifiedName($name); Chris@0: $inScope = isset($this->currentScope[strtolower($fullName)]); Chris@0: if (!$inScope && !function_exists($shortName) && !function_exists($fullName)) { Chris@0: $message = sprintf('Call to undefined function %s()', $name); Chris@0: throw new FatalErrorException($message, 0, E_ERROR, null, $node->getLine()); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: private static function isConditional(Node $node) Chris@0: { Chris@0: return $node instanceof If_ || Chris@0: $node instanceof While_ || Chris@0: $node instanceof Do_ || Chris@0: $node instanceof Switch_; Chris@0: } Chris@0: }