Re: This isn't infinitely recursive is it?
| From: | Ben Dunlap | Date: | Fri, 31 Jul 2009 00:04:42 +0000 |
| Subject: | Re: This isn't infinitely recursive is it? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296084@lists.php.net to get a copy of this message | ||
> 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