Practice extracting variables Is better to use $id_name ( Class A Method b() ) OR $id_name_2 ( Class A Method c())?

&lt;?php

Class A { 

    function a(){
        $params = array(
            'id'=&gt; 1,
            'name' =&gt; 'b',
        );

        $id_name = $this-&gt;b($params);
        $id_name_2 = $this-&gt;c($params);
    }

    function b($params){
        $id = $params['id'];
        $name = $params['name'];
        /*******

            Some code performing operations with $name and $id

        ********/

        $str = $id . $name; 
        return $str;
    }


    function c($params){

        /*******

            Some code performing operations with $params['name'] and $params['id']

        ********/

        $str = $params['name'] . $params['id'];

        return $str;
    }

}
Using method c will have an side-effect if $params is modified. This is because arrays are passed by reference, and so any changes to $params will be visible to the caller when the function returns. Use b if you need to manipulate id or name, unless you intend to return the modifications to the caller.

Example:

$params = array('id' =&gt; 1, 'name' =&gt; 'b');
$this-&gt;d($params);
echo $params['id']; // outputs 2
...

function d($params) {
    $params['id']++;
}