<div dir="ltr">Users always find a way to get bad data into the system.  ;)  I have added a ton of referential integrity to our fork of vtiger and crap still makes it in periodically.<div><br></div><div style>Check out this tutorial [3] on tail recursion and accumulators.  Basically you'll just accumulate an array of userids and use in_array to make sure that you don't process the same userid twice.  PHP doesn't optimize for tail recursion, so I would recommend writing it as a loop inside a function.</div>
<div style><br></div><div style>[3] <a href="http://siddhi.blogspot.com/2006/04/recursion-part-2-tail-recursion.html">http://siddhi.blogspot.com/2006/04/recursion-part-2-tail-recursion.html</a><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 11:40 AM, salim <span dir="ltr"><<a href="mailto:salimcmd@gmail.com" target="_blank">salimcmd@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Adam,<br>    You saying that make two users to report to each other, like  <b>UserA </b>---> <b>UserB</b> , <b>UserB ---> UserA</b>. Will it happen in real scenario?
<div>If so this will happen <a href="http://pastebin.com/jrFmBnxS" target="_blank">http://pastebin.com/jrFmBnxS</a>. It dropped in a infinite loop.  :P</div><div><br></div><div>How you proposing accumulator in Recursive function.</div>


<div><br></div><div>Thanks</div><div>--</div><div>Salim</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On 30 April 2013 20:14, Adam Heinz <span dir="ltr"><<a href="mailto:amh@metricwise.net" target="_blank">amh@metricwise.net</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Ooooooh, reverse that again, it could be cyclic, even though that would make so sense, the system does not enforce it.  Definitely need the accumulator to avoid an infinite loop.  Set two users to report to each other and see if it explodes.  ;)</div>


<div><div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 10:14 AM, Adam Heinz <span dir="ltr"><<a href="mailto:amh@metricwise.net" target="_blank">amh@metricwise.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div dir="ltr"><div>On Tue, Apr 30, 2013 at 10:12 AM, Adam Heinz <span dir="ltr"><<a href="mailto:amh@metricwise.net" target="_blank">amh@metricwise.net</a>></span> wrote:<br></div><div class="gmail_extra">
<div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You should add some sort of accumulator to getReportingUsers so that you don't recur for userids you have already checked.</div>




</blockquote><div><br></div></div><div>Scratch this comment, we're walking a directed acyclic graph; redundancy is impossible.</div></div></div></div>
</blockquote></div><br></div>
</div></div><br></div></div>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><span class="HOEnZb"><font color="#888888"><br></font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div>
<br></div>-- <br>Muhammed Abdul Salim<br>
</font></span></div>
<br>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br></blockquote></div><br></div>