Re: [PHP3] Re: [PHP4BETA] Re: [PHP3] OO
| From: | Manuel Lemos | Date: | Wed, 04 Aug 1999 23:32:38 +0000 |
| Subject: | Re: [PHP3] Re: [PHP4BETA] Re: [PHP3] OO | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3131@lists.php.net to get a copy of this message | ||
Hello Zeev,
On 05-Aug-99 00:28:37, you wrote:
>I think I need to clear up why there'll be no destructors in PHP,
>regardless of whether you think they may make some things a bit more
>elegant (that said, I haven't followed the thread about
>register_shutdown_function() closely, but you can register as many shutdown
>functions as you wish, and they'll be executed in the order they were
>registered).
There is no mention in the documentation about being able to register more
than one shut down function. Does that work like that in PHP 3 too?
This is just to remind how important is for documentation to be explicit.
This also reminds of me of a POP3 class that I wrote once upon a long time
ago before IMAP library support was added.
Despite that with IMAP library you can talk to POP3 servers, a lot of
people are still looking for the class because it is not explicit in the
front page of the manual that it supports POP3.
Maybe you should have a section in the manual POP3 support and inside it it
would say something like:
"POP3 support is implemented with the IMAP library. IMAP library does not
require a IMAP server to handle POP3 connections, any plain POP3 server can
be accessed with the PHP IMAP support, see imap_open for more information."
People are not that dumb, it is just that they don't guess implicit things.
>Why not just invoke the destructor when the reference count of the object
>hits zero? In a better world, that would be a valid solution. But we're
>here, and it's not. For technical reasons, in quite a few cases, values
>actually get duplicated and not just refcount-increased. That would mean a
>single instance of the object will duplicate, and two instances of the
>object, with two separate reference counts would exist in memory. When the
>first one hits zero - the destructor will be invoked. And then the second
>one would hit zero, and the destructor would be invoked again.
I believe that just like you don't have copy constructors and programmers
don't assume that the constructor method is called on copy, you could have a
destructor method that would be called eventually more than once for the same
instance if that is the case and the programmers should be aware that it
may happen.
For instance, a destructor could close a file geting the identifier from a
instance variable and would set to 0 to prevent closing it again:
class some_class
{
$file=0;
Function Destructor()
{
if($this->file)
{
fclose($this->file);
$this->file=0;
}
}
...
}
>A final note - I'll look into making the shutdown functions accept
>arguments before PHP 4.0 Beta 3 (Beta 2 will be out within a few
>days). This way you won't have to use global variables - instead, you could
>do
Great. BTW, couldn't you add a similar support to XML call functions. You
could have something like xml_set_handler_object($parser,$object) and then
instead of calling global functions the handlers would call the object
methods.
Regards,
Manuel Lemos
Web Programming Components using PHP Classes.
Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org
--
E-mail: mlemos@acm.org
URL: http://www.mlemos.e-na.net/
PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp
--