ID:               31700
 User updated by:  attibln at gmx dot net
 Reported By:      attibln at gmx dot net
-Status:           Bogus
+Status:           Open
 Bug Type:         Class/Object related
 Operating System: linux
 PHP Version:      5.0.3
 New Comment:

Well I do not really want to do nitpicking, but why is it called
__destruct() if it does _not_destruct_?! Wouldn't be __exit_method()
and __start_method() better choosen then?!

As #31701 this behaviour is not real object oriented behaviour. In my
opinion the engine should unset an object when __destruct() is called -
similar as it's done in other OOL like C++.

To my surprise unset($obj) really executes __destruct(). This should be
mentioned in the _documentation_ "Classes & Objects (PHP5) Constructor &
Destructor". Additionally advising not to call __destruct() explicitly
but using unset() - as it's stated to use keyword new to create an
object instead of __construct(). An example:

<?php

class MyDestructableClass {
  function __construct() {
    print "<br />In constructor\n";
    $this->name = "MyDestructableClass";
  }

  function __destruct() {
    print "<br />Destroying " . $this->name . "\n";
  }
}

$obj = new MyDestructableClass();
unset( $obj );

?>


Previous Comments:
------------------------------------------------------------------------

[2005-01-26 09:05:09] [EMAIL PROTECTED]

This is expected. To destroy an object use: unset($obj);

------------------------------------------------------------------------

[2005-01-26 02:51:43] attibln at gmx dot net

Description:
------------
On second call of __destruct() there should be an error message like
"object not existing".

(http://www.php.net/manual/de/language.oop5.decon.php)
"PHP 5 introduces a destructor concept <b>similar to that of other
object-oriented languages, such as Java</b>. The destructor method will
be called as soon as all references to a paticular object are removed or
when the object is <b>explicitly destroyed</b>."

My system:
gentoo 2.4.26-gentoo-r9
apache 2.0.51-r1
PHP Version 5.0.3 / Zend Engine v2.0.3

(php) use flags:
-adabas +apache2 -bcmath -berkdb -birdstep +bzlib -calendar -cdb
-cpdflib +crypt -ctype +curl +curlwrappers -db2 -dba -dbase -dbm
-dbmaker -dbx -debug -dio -empress -empress-bcs -esoob +exif -fam
-fdftk -filepro -flatfile -frontbase -ftp +gd -gd-external -gdbm -gmp
-hyperwave-api -iconv -imap -informix -ingres -inifile -interbase
-iodbc +jpeg -kerberos -ldap -libedit -mcve +memlimit -mhash +mime
-ming -mnogosearch -msession -msql -mssql +mysql -mysqli +ncurses -nis
+nls -oci8 -odbc -oracle7 -ovrimos +pcntl -pcre -pfpro +png -posix
+postgres -qdbm -readline -recode -sapdb -sasl +session -shared
-sharedmem +simplexml -snmp +soap +sockets -solid -spell +spl -sqlite
+ssl -sybase -sybase-ct -sysvipc +tidy -tiff +tokenizer -truetype -wddx
+xml2 -xmlrpc -xpm +xsl +zlib

Reproduce code:
---------------
<?php

class MyDestructableClass {
  function __construct() {
    print "<br />In constructor\n";
    $this->name = "MyDestructableClass";
  }

  function __destruct() {
    print "<br />Destroying " . $this->name . "\n";
  }
}

$obj = new MyDestructableClass();
print( '<br />before destruction' );
$obj->__destruct();
$obj->__destruct();
$obj->__destruct();
print( '<br />before script end' );

?>


Expected result:
----------------
something like:

Fatal error: ... Destruction of not existing object ist not possible!
... in ... on line ...

Actual result:
--------------
Explicit destruction "not possible".
In other words:
Calling __destruct on an object is possible as often it is done.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=31700&edit=1

Reply via email to