Re: This isn't infinitely recursive is it?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I don't THINK I need to worry about circular mappings... but I'm not
> sure how to check for it if I did...
> 
> Any suggestions? Thanks!

Would the following work? It avoids recursion entirely and also checks for
circular mappings. You can plug in your own code where the comments are to do
whatever is appropriate when a circular mapping is detected.

function GetMappedField($Field)
{
    $OriginalField = $Field;

    while (isset($FieldMap[$Field]) {
        $Field = $FieldMap[$Field];

        if ($Field === $OriginalField) {
            /*
             * circular mapping has been detected;
             * report an error or explode or whatever
             */
             break;
        }
    }

    return $Field;
}


Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux