title: Why is my __clone() not working as expected?
body: <p>So I am using the code below in one of my PHP classes (within a larger library):</p>
  
  <pre><code>public function __clone() {
      // recreate this class in its' current state
      $new = new \uri(\uri\generate::string($this-&gt;object));
      // give it the same origin
      $new-&gt;input = $this-&gt;input;
      // now send the new instance back
      return $new;
  }
  </code></pre>
  
  <p>In short, I need to recreate the class rather than a traditional clone. However, whenever I use <code>clone</code>, it is still returning a regular clone rather than a new instance.</p>
  
  <p>I need to make a new instance because of how reference variables are used within the class.</p>
  
  <p>--</p>
  
  <p>My testing script:</p>
  
  <pre><code>$uri1 = new uri('example.com');
  $uri2 = clone $uri1;
  
  $uri2-&gt;host = 'google.com';
  
  // __toString() returns the URI in its' current state
  echo $uri1.PHP_EOL.$uri2;
  </code></pre>
  
  <p>The <strong>expected</strong> output of the test:</p>
  
  <pre><code>example.com
  google.com
  </code></pre>
  
  <p>The <strong>actual</strong> output of the test:</p>
  
  <pre><code>google.com
  google.com
  </code></pre>
  
  <p>&nbsp;</p>
  
  <p><strong>My Question:</strong> What am I doing wrong?</p>
  
  <p>I am using PHP 5.5.6</p>
  
  <hr>
  
  <p>For those who need complete context see the link below (lines <strong>145</strong> to <strong>152</strong>). Be warned, there is a lot.</p>
  
  <p><a href="https://gitlab.com/projectcleverweb/php-uri/blob/20417ea5d0a419b54c5243a8b1680310ec2594eb/uri.lib.php" rel="nofollow">The library in question</a></p>