php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27698 class destructor
Submitted: 2004-03-25 12:20 UTC Modified: 2004-03-31 11:59 UTC
Votes:5
Avg. Score:3.6 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:4 (100.0%)
From: eyglys at yahoo dot com dot br Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.0.0RC1 OS: Windows
Private report: No CVE-ID: None
 [2004-03-25 12:20 UTC] eyglys at yahoo dot com dot br
Description:
------------
Destructor method is actived two times

Reproduce code:
---------------
/* source code */
<?
class t {

	function __construct() {
		echo "constructor\n";
	}

	function __destruct() {
		echo "destructor\n";
	}
}

$p = new t();
?>

Expected result:
----------------
/* the output expected is */

constructor
destructor

Actual result:
--------------
/* the result output */

constructor
destructor
destructor

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-25 12:29 UTC] derick@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


Can't reproduce; works just fine.
 [2004-03-31 11:59 UTC] iliaa@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2005-06-14 16:21 UTC] Ancien_Guakamol at hotmail dot com
Well in fact it seams to be a cause of IIS server, implicit call of destructor is done before the end of the script

something like that :
class Object
{
  public function __construct()
  {
      ...
      ...
      echo 'end __construct';
  }
public function __destruct()
  {
      ...
      ...
      echo 'end __destruct';
  }
}
echo 'Construct';
$obj = new Object();
echo 'Done';

Will result :

Construct
end __construct
end __destruct
Done

I tried this script on IIS Server and Apache Server both with PHP 5.0.4

On Apache right result but not on IIS
 [2008-12-05 15:32 UTC] evgenius at mail dot by
I have the same problem.
-------------------------
PHP Version 5.2.6
Build Date: May 2 2008 18:01:20
Configure Command: cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" "--with-extra-includes=C:\Program Files (x86)\Microsoft SDK\Include;C:\PROGRA~2\MICROS~2\VC98\ATL\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\MFC\INCLUDE" "--with-extra-libs=C:\Program Files (x86)\Microsoft SDK\Lib;C:\PROGRA~2\MICROS~2\VC98\LIB;C:\PROGRA~2\MICROS~2\VC98\MFC\LIB"
PHP API 	20041225 
PHP Extension 	20060613 
Zend Extension 	220060519 
Debug Build 	no 
Thread Safety 	enabled
-------------------------
OS: windows XP Professional SP2 32bit
Apache 2.2.10
-------------------------
#############################################
I wouldn't copy the source code from the first message, but I'll add that if you use
$p = & new t();
instead of
$p = new t();
everything is going like it was expected.
Hope my message is enought informative. It is very annoying problem.
 [2008-12-05 16:22 UTC] evgenius at mail dot by
After several minutes of testing I found out that destructor isn't invoked (after creating an instance) if the constructer has parameters. So without parameters the destructor is invoked twice(first after creating, then after destruction the last link).
-------------------------------------
<?php
class t {	
	
	function __construct($new) {
		echo "constructor\n";		
	}

	function __destruct() {
		echo "destructor\n";
	}
}

$p = & new t($new);
?>
------------------------------------
//Out:
constructor
destructor
-------------------------------------
<?php
class t {	
	
	function __construct() {
		echo "constructor\n";		
	}

	function __destruct() {
		echo "destructor\n";
	}
}

$p = & new t($new);
?>
-------------------------------------
//Out:
constructor
destructor
destructor
-------------------------------------
So "& new t($new)" (param $new is requered) and parameters in definition of the constructor make it work right.
 [2008-12-05 19:22 UTC] evgenius at mail dot by
No more questions ...
switched zend.ze1_compatibility_mode off and problem gone.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC