PHP - Problem with scalar value and memory leak
<p>I am dealing with a very strange situation that has to do with the <code>Warning: Cannot use a scalar value as an array and memory leak.</code></p>

<p>The script is very simple and I can not figure out the problem.</p>

<p><strong>Code</strong></p>

<pre><code>$variants=array();                                  
if($text) 
{ 
    $v=explode(",",$text);
    if(is_array($v) &amp;&amp; sizeof($v)&gt;0)
    {
         foreach($v as $i=&gt;$part)
         {                                      
        $tmp=explode(":",$part);
            list($thekey,$thevalue)=$tmp;
        //$variants=array(); 
        echo "&lt;div&gt;TYPE==".gettype($variants)."&lt;/div&gt;";
        echo $variants[$tmp[0]]=$tmp[1];    
         }
    }
}
</code></pre>

<p>If I run the code above as stand alone is working fine. But when put it in my framework as small part behave very strange. I got a <code>Warning: Cannot use a scalar value as an array</code> and in order to solve it I added </p>

<pre><code>$variants=array();  
</code></pre>

<p>on the first line. When running the script the <code>gettype</code> returns <code>���</code> the first time and after that return integer.</p>

<p>If i uncomment <code>$variants=array();</code> just before the <code>gettype</code>, it works. But of course I don't to get the whole array, only the last record return.</p>

<p>I parse my code to find out that the variables I use are declared before I even change all the variable names to stupids but no luck.</p>

<p>Trying to debug and tune the code where times that when running the script instead of see something in the screen the browser download the script instead and some other times I had memory leaks.</p>

<p>Can anyone point where or what to look for, or debug it and solve it?</p>
