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