title: PHP null and copy-on-write
body: <p>Suppose I want to have two variables and have them both equal to <code>null</code>. (More realistically, I am thinking about an array that contains a large amount of <code>null</code>s, but the "two variables" scenario is sufficient for the question.) Obviously, I can do this in more than one way. I can do this (method 1):</p>
  
  <pre><code>$a = null;
  $b = $a;
  </code></pre>
  
  <p>By my understanding, the result of this is that there is one zval that is pointed to by two entries in the symbol table: <code>'a'</code> and <code>'b'</code>. But alternatively one might do this (method 2):</p>
  
  <pre><code>$a = null;
  $b = null;
  </code></pre>
  
  <p>Naively one would expect that this should result in two different zvals, each pointed to by one entry in the symbol table.</p>
  
  <p>Does it follow from this that if you want to have a large array, and many elements of the array will be <code>null</code>, it's more efficient (in terms of zval/memory use) to create a <code>$master_null</code> variable with the value <code>null</code>, and then write the <code>null</code> elements of the array by assigning using <code>$master_null</code>?</p>