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;
?>


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to