php - Issue with passing reference of variable -


<?php  function requestsecond($param) {     $param['conf']++; }  function requestfirst($params) {     $params['conf']++;     requestsecond($params); }  $conf = 1; requestfirst(array(     'conf' => &$conf, )); echo $conf; 

result: 3

question:

i know &$conf means pass reference of $conf, understand after requestfirst($params), $conf=2, not understand why after requestsecond($param), $conf=3, requestsecond($param); pass reference of $conf not value?

$conf in requestfirst reference, still reference when pass new function. reference if assign local variable inside requestfirst.

eg:

function requestfirst($params) {   $params['conf']++;       $stillreference = $params; // $stillreference hold reference $conf   $local = array( 'conf' => $params['conf']); // local , output 2   requestsecond($stillreference); //outputs 3 } 

in above example there no difference between $params , $stillreference , both using same internal variable container. way separate these 2 invalidating 1 of variables using unset().


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -