Destroy an object inside the object itself
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2214724/php-constructor-to-return-a-null">PHP constructor to return a NULL</a>  </p>
</blockquote>



<p>I'm writing a class: its constructor takes one parameters. If the parameter is not valid, I want to print an error message (with the code of the error) and return NULL as the object instance, so that I can check in the "main" if the creation went well by (!$object). How do I achieve this? How do I exit the constructor leaving behind a null reference for the object?</p>

<pre><code>class test
{
    public function __construct($var)
    {
        if($var &gt; 100)   { /* stop the creation, print the error and set the this instance to null */ }
    }

    public function __destruct($code)
    {
        print "error code = $code";
        /* destroy and return */
    }
}
</code></pre>
