destroy the current object (PDO)

From: Date: Wed, 09 Apr 2008 08:14:56 +0000
Subject: destroy the current object (PDO)
Groups: php.internals 
Request: Send a blank email to internals+get-36897@lists.php.net to get a copy of this message
Hello, I would like to correct a little "problem" with : when an error occured in the constructor (a connection error for example) no object is returned. Internally, the object is created then destroyed (via "ZVAL_NULL(object);" statement). The problem is when the PDO class is derived and the error catched in the "child" constructor : $this is destroyed, but the object still exists in memory (and the __destruct will be called at the end of the script). Is there a way here to really destroy the object ? I submit a bug report (44669), but C. Rodriguez seems to don't agree with me. So I would like to correct the problem myself but... I can't :D I join here a better example of this behaviour : <?php class PDOtest extends PDO { public function __construct( $dsn, $user, $password ) {
       try {
           parent::__construct( $dsn, $user, $password );
       } catch( PDOException $e ) {
           echo 'there is an error... but continue the script', PHP_EOL;
       }
} public function __destruct() {
       echo 'DESTRUCT ::: If called, then the object was existing', PHP_EOL;
} } echo 'CONSTRUCT ::: '; $test = new PDOtest( 'mysql:host=localhost;dbname=test', 'baduser', 'orpass' ); echo PHP_EOL; echo 'Here you can see that the object is "destroyed" : '; var_dump( $test ); echo 'But force to null, to be sure.', PHP_EOL; $test = NULL; echo PHP_EOL, 'SOME WORKS', PHP_EOL; ?>

« previous php.internals (#36897) next »