php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44669 object not immediately destructed on error
Submitted: 2008-04-08 08:58 UTC Modified: 2008-04-08 21:46 UTC
From: ob dot php at daevel dot fr Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.5 OS: Debian Lenny (testing)
Private report: No CVE-ID: None
 [2008-04-08 08:58 UTC] ob dot php at daevel dot fr
Description:
------------
Hello,

when catching a connection error in a class extending PDO, the object is not destroyed before end of script.
It's really not a big bug, but as the instance is not usable (no instance is returned at all) it should be destroyed no ?



Reproduce code:
---------------
<?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;
        	return;
        }
	}

    public function __destruct()
    {
        echo 'DESTRUCT', PHP_EOL;
    }
}

echo 'CONSTRUCT', PHP_EOL;
$test = new PDOtest( 'mysql:host=localhost;dbname=test', 'baduser', 'orpass' );
var_dump( $test );

echo 'SOME WORKS', PHP_EOL;
?>

Expected result:
----------------
CONSTRUCT
there is an error... but continue the script
DESTRUCT
NULL
SOME WORKS


Actual result:
--------------
CONSTRUCT
there is an error... but continue the script
NULL
SOME WORKS
DESTRUCT


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-08 19:14 UTC] crrodriguez at suse dot de
This is the expected behaviuor, objects are destroyed at script shutdown.
 [2008-04-08 19:31 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2008-04-08 21:46 UTC] ob dot php at daevel dot fr
But here no object is returned... 

And thince PHP 5 objects are destroyed when the last "reference" is destroyed, no ? This example is the only case where I see PHP 5 not destroy correctly an object.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 15:01:29 2024 UTC