How check memory location of variable in php?

前端 未结 6 1182
旧时难觅i
旧时难觅i 2020-12-06 10:05

How check memory location of variable in php?

Thanks

6条回答
  •  忘掉有多难
    2020-12-06 10:53

    As others have said, the API does not expose a way to retrieve a value's address. However, you can compare the addresses of two values, given two variables. Here's a function that tests whether two variables reference the same value:

    function vars_reference_same_value(&$a, &$b)
    {
      $not_b = $b === 0 ? 1 : 0;
      $a_orig = $a;
      $a = $not_b;
      $is_ref = $b === $not_b;
      $a = $a_orig;
      return $is_ref;
    }
    

    (This is the same as @infinity's answer, but perhaps more comprehensible.)

提交回复
热议问题