私が間違っていると誰かが私を修正しますが、PHPは現時点で実際に再帰を検出しています。あなたの割り当ては、単に追加のサイクルを作成するだけです。例は次のようになります。予想通り
array(1) { [0]=> &array(1) { [0]=> *RECURSION* } }
になります
$arr = array();
$arr = array(&$arr);
。
再帰を検出する方法はちょっと不思議ですが、私はGoogleに着手しました。そのためPHPの呼び出しごとの値メカニズムの
function hasRecursiveDependency($value)
{
//if PHP detects recursion in a $value, then a printed $value
//will contain at least one match for the pattern /\*RECURSION\*/
$printed = print_r($value, true);
$recursionMetaUser = preg_match_all('@\*RECURSION\*@', $printed, $matches);
if ($recursionMetaUser == 0)
{
return false;
}
//if PHP detects recursion in a $value, then a serialized $value
//will contain matches for the pattern /\*RECURSION\*/ never because
//of metadata of the serialized $value, but only because of user data
$serialized = serialize($value);
$recursionUser = preg_match_all('@\*RECURSION\*@', $serialized, $matches);
//all the matches that are user data instead of metadata of the
//printed $value must be ignored
$result = $recursionMetaUser > $recursionUser;
return $result;
}
lol - eeewwwww。 – leeoniya
あなたの質問に対する答えではありませんが、再帰を示す文字列に対して 'print_r($ var、true) 'をテストするソリューションがあります。これはあなたが得ることができるほど厄介ですが、うまくいきます...適切な妥協のために[ここ](http://noteslog.com/post/detecting-recursive-dependencies-in-php-composite-values/)を参照してください。 – Basic
例へのリンクを含むように私のコメントを削除/編集しましたが、私は同意します。それは臭いです – Basic