Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Someone will correct me if I am wrong, but PHP is actually detecting recursion at the right moment. Your assignation simply creates the additional cycle. The example should be:</p> <pre><code>$arr = array(); $arr = array(&amp;$arr); </code></pre> <p>Which will result in</p> <pre><code>array(1) { [0]=&gt; &amp;array(1) { [0]=&gt; *RECURSION* } } </code></pre> <p>As expected.</p> <hr> <p>Well, I got a bit curious myself how to detect recursion and I started to Google. I found this article <a href="http://noteslog.com/post/detecting-recursive-dependencies-in-php-composite-values/" rel="nofollow">http://noteslog.com/post/detecting-recursive-dependencies-in-php-composite-values/</a> and this solution:</p> <pre><code>function hasRecursiveDependency($value) { //if PHP detects recursion in a $value, then a printed $value //will contain at least one match for the pattern /\*RECURSION\*/ $printed = print_r($value, true); $recursionMetaUser = preg_match_all('@\*RECURSION\*@', $printed, $matches); if ($recursionMetaUser == 0) { return false; } //if PHP detects recursion in a $value, then a serialized $value //will contain matches for the pattern /\*RECURSION\*/ never because //of metadata of the serialized $value, but only because of user data $serialized = serialize($value); $recursionUser = preg_match_all('@\*RECURSION\*@', $serialized, $matches); //all the matches that are user data instead of metadata of the //printed $value must be ignored $result = $recursionMetaUser &gt; $recursionUser; return $result; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload