Detecting cyclic (recursive) arrays in pure PHP is fundamentally impossible due to how PHP handles value assignments of arrays containing references. The post walks through a naive marker-based detection algorithm, then demonstrates how a specially crafted array returned from a function causes infinite recursion. The root cause
Table of contents
Attempting a pure PHP solutionBreaking the pure PHP solutionWhat is going on inside the arrayArrays cannot be trustedThe morale of this storyWrapping upSort: