PHP: check if object/array is a reference

后端 未结 5 2033

Sorry to ask, its late and I can\'t figure a way to do it... anyone can help?

$users = array(
    array(
        \"name\" => \"John\",
        \"age\"   =         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 15:53

    function var_reference_count(&$xVal) {
        $ao = is_array($xVal)||is_object($xVal);
    
        if($ao) { $temp= $xVal;    $xVal=array();    }
    
        ob_start();        
         debug_zval_dump(&$xVal);
        $dump = ob_get_clean();
    
        if($ao) $xVal=$temp;
    
        preg_match('/refcount\((\d*)\)/',$dump,$matches);
        return $matches[1] - 3;
    }
    //-------------------------------------------------------------------------------------------
    

    This works with HUDGE objects and arrays.

提交回复
热议问题