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