{"record":{"id":"8f002a82f7e8dd23","repo":"nikic/PHP-Parser","slug":"leavenode-may-only-return-an-array-if-the-parent","errorCode":null,"errorMessage":"leaveNode() may only return an array if the parent structure is an array","messagePattern":"leaveNode\\(\\) may only return an array if the parent structure is an array","errorType":"exception","errorClass":"\\LogicException","httpStatus":null,"severity":"error","filePath":"lib/PhpParser/NodeTraverser.php","lineNumber":160,"sourceCode":"                }\n            }\n\n            for (; $visitorIndex >= 0; --$visitorIndex) {\n                $visitor = $this->visitors[$visitorIndex];\n                $return = $visitor->leaveNode($subNode);\n\n                if (null !== $return) {\n                    if ($return instanceof Node) {\n                        $this->ensureReplacementReasonable($subNode, $return);\n                        $subNode = $node->$name = $return;\n                    } elseif (NodeVisitor::STOP_TRAVERSAL === $return) {\n                        $this->stopTraversal = true;\n                        break 2;\n                    } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) {\n                        $node->$name = null;\n                        break;\n                    } elseif (\\is_array($return)) {\n                        throw new \\LogicException(\n                            'leaveNode() may only return an array ' .\n                            'if the parent structure is an array'\n                        );\n                    } else {\n                        throw new \\LogicException(\n                            'leaveNode() returned invalid value of type ' . gettype($return)\n                        );\n                    }\n                }\n            }\n        }\n    }\n\n    /**\n     * Recursively traverse array (usually of nodes).\n     *\n     * @param Node[] $nodes Array to traverse\n     *","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/nikic/PHP-Parser/blob/fbd47f7ebcbb450138d92642a0a53b72a5285dda/lib/PhpParser/NodeTraverser.php#L142-L178","documentation":"Error \"leaveNode() may only return an array if the parent structure is an array\" thrown in nikic/PHP-Parser.","triggerScenarios":"Thrown at lib/PhpParser/NodeTraverser.php:160 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fbd47f7ebcbb450138d92642a0a53b72a5285dda","analyzedAt":"2026-08-17T03:58:32.123Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}