Recursion detected¶
Description¶
The compact
function accepts an array of arguments. The function is actually recursive, and searches for everything recursively. This leads to potential infinite recursion, if the provided array contains a link to itself.
Example¶
<?php
$a = 1;
$arr1 = array('a', &$arr1);
try {
var_dump(compact($arr1));
} catch (Error $e) {
echo $e->getMessage() . \n;
}
?>
Solutions¶
Flatten the array into one level only.
Remove the self references.
Do not use array known to host self references, such as
$GLOBALS
.