title: CakePHP setting multiple values into one cookie
body: <p>I know that multiple values can be set to cookie this way:</p>
  
  <pre><code>If you want to write more than one value to the cookie at a time,
      you can pass an array:
  
  $this-&gt;Cookie-&gt;write('User',
      array('name' =&gt; 'Larry', 'role' =&gt; 'Lead')
  );
  </code></pre>
  
  <p>Due to some design issues, I need to set cookie values in different parts of my controller action. But it seems like this minimalized code doesn't work:</p>
  
  <pre><code>public function myfunction() {
      $text = "";
      // to be sure that this cookie doesn't exist
      $this-&gt;Cookie-&gt;delete('mycookie');
      // getting data from cookie, result is NULL
      $data = $this-&gt;Cookie-&gt;read('mycookie');
      $text .= "data 1 type: ".gettype($data)."&lt;br&gt;";
      $key="mike";
      $value=12;
      // adding key-value to cookie
      $data[$key] = $value;
      // serializing and writing cookie
      $dataS = json_encode($data);
      $this-&gt;Cookie-&gt;write('mycookie', $dataS, FALSE, '10 days');
  
      // reading cookie again, but this time result is
      // string {"mike":12} not an array
      $data = $this-&gt;Cookie-&gt;read('mycookie');
      $text .= "data 2 type: ".gettype($data)."&lt;br&gt;";
      $key="john";
      $value=20;
      // Illegal string offset error for the line below
      $data[$key] = $value;
      $dataS = json_encode($data);
      $this-&gt;Cookie-&gt;write('mycookie', $dataS, FALSE, '10 days');
  
      echo $text;
  
  }
  </code></pre>
  
  <p>Page output:  </p>
  
  <pre><code>Warning (2): Illegal string offset 'john' [APP/Controller/MyController.php, line 2320]  
  data 1 type: NULL   
  data 2 type: string  
  </code></pre>
  
  <p>From the code above, "Mike 12" is set to cookie successfully. But when I read cookie data for the second time, I get a string like this: <code>{"mike":12}</code>. Not an array.</p>
  
  <p>When I make <code>gettype</code> for "data 2" the output is "string".<br>
  So when I make <code>$data["john"]=20</code> I get <code>Illegal string offset error</code> because <code>$data</code> is string not array.</p>
  
  <p>So is it not possible to set same cookie in an action, one by one ?</p>
  
  <p>Edit:
  When I create a data array, json_encode that array and write its contents to cookie. Then when in another controller, when I read that cookie contents and assign it so a variable, it is automatically converted to Array.</p>