- var_dump: documentation ( source)
- count: documentation ( source)
- restore_error_handler: documentation ( source)
- set_error_handler: documentation ( source)
- mb_stripos: documentation ( source)
<?php
function is_cyclic(&$array) {
$isRecursive = false;
set_error_handler(function ($errno, $errstr) use (&$isRecursive) {
$isRecursive = $errno === E_WARNING && mb_stripos($errstr, 'recursion');
});
try {
count($array, COUNT_RECURSIVE);
} finally {
restore_error_handler();
}
return $isRecursive;
}
$array = [1, [2, 3]];
$array[1][1] = &$array;
var_dump(is_cyclic($array));