Chris@0: functionDepth = 0; Chris@0: } Chris@0: Chris@0: public function enterNode(Node $node) Chris@0: { Chris@0: if ($node instanceof FunctionLike) { Chris@0: $this->functionDepth++; Chris@0: Chris@0: return; Chris@0: } Chris@0: Chris@0: // node is inside function context Chris@0: if ($this->functionDepth !== 0) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // It causes fatal error. Chris@0: if ($node instanceof Yield_) { Chris@0: $msg = 'The "yield" expression can only be used inside a function'; Chris@0: throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * @param \PhpParser\Node $node Chris@0: */ Chris@0: public function leaveNode(Node $node) Chris@0: { Chris@0: if ($node instanceof FunctionLike) { Chris@0: $this->functionDepth--; Chris@0: } Chris@0: } Chris@0: }