title: Clone PHP object and set protected property on clone
body: <p>I got a logical problem.</p>
  
  <p>I got an object that needs to be cloned.</p>
  
  <p>The object is|has a result of a calculation.</p>
  
  <p>The object has a runtime.</p>
  
  <p>In some cases it is faster to clone the object instead of calculating the result again </p>
  
  <p><em>(f.e. same parameter ^= same result)</em>.</p>
  
  <p><strong>But</strong> the runtime must <strong>not</strong> be copied.</p>
  
  <p>The runtime would be the time to determine that i can use the same result (object).</p>
  
  <p>Example:</p>
  
  <pre><code>class Object
  {
      protected $runtime;
  
      public function getRuntime()
      {
          return $this-&gt;runtime;
      }
  
      public function doSome(/*...*/)
      {
          $start = microtime(true);
          // ... the heavy work ...
          // ...
          $this-&gt;runtime = microtime(true) - $start;
      }
  }
  
  $objects = [];
  while (/*...*/) {
      if (count($objects) &gt; 0) {
          $start = microtime(true);
          if (/*check if would get the same result as the previous one*/) {
              $object = clone end($objects);
              // MUST change the runtime here on the clone 
              // but i should not make :runtime public
              $object-&gt;runtime = microtime(true) - $start; // :(
              $objects[] = $object;
              continue;
          }
      }
      $object = new Object();
      $object-&gt;doSome(/*...*/);
      $objects[] = $object;
  }
  </code></pre>
  
  <p>How could i clone the previous object and set the actual runtime on the clone without making it possible to make the runtime property public?</p>