473,216 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

destructors

So if I don't have anything specific to do when an object is no
longer referenced, I don't have to explicitly define a destructor
method? I am not required to free or delete each variable, am I?

Thanks, Mike

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 16 '05 #1
5 1333
Mike G schrieb:
So if I don't have anything specific to do when an object is no
longer referenced, I don't have to explicitly define a destructor
method? I am not required to free or delete each variable, am I?

Normally you don't need a destructor. Because objects are only valid in
their scope.

function foo() {
$bar = new Something()
}

$bar will be created and destroyed everytime foo is called.

However you may want to have an explitzit destructor:
eg.

class Something{
var $fp;
// constructor
function Something(
$this->fp=fopen("somefile","r");
}

// now you need to close the file when something is destroyed

//destructor
// watch the underscore
function _Something(
fclose($this->fp);
}
Hope it helps!

Jo
Aug 16 '05 #2
"Mike G" <mi****@montana.com> wrote in message
news:11*************@spool6-east.superfeed.net...
So if I don't have anything specific to do when an object is no
longer referenced, I don't have to explicitly define a destructor
method? I am not required to free or delete each variable, am I?


In terms of freeing memory it makes sense that it isn't really an
issue with web applications. Once a request (script) has been
responded to, the server automagically restores the memory
used by the script.

Mike

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 16 '05 #3
Joachim Weiß wrote:
//destructor
// watch the underscore
function _Something(
fclose($this->fp);
}


I'm watching it, but all I can see is that you possibly mean the
__destruct() method available in PHP5...
JW

Aug 16 '05 #4
Janwillem Borleffs schrieb:
Joachim Weiß wrote:
//destructor
// watch the underscore
function _Something(
fclose($this->fp);
}

I'm watching it, but all I can see is that you possibly mean the
__destruct() method available in PHP5...
JW

Your right! I mixed it up with something else!
class Something{
var $fp;

class Something {
function __construct() {
$this->fp=fopen("somefile","r");
}

function __destruct() {
fclose($this->fp);
}

}
Aug 16 '05 #5
Following on from Joachim Weiß's message. . .
function foo() {
$bar = new Something()
}

$bar will be created and destroyed everytime foo is called.


Q: As far as the PHP script is concerned $bar no longer exists and if
foo() is called again another $bar is created - That's fine.

But what is the garbage collection situation during the running of the
script, which could be important for large objects?
--
PETER FOX Not the same since the bookshop idea was shelved
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Aug 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rajesh Garg | last post by:
Can we have private constructors and destructors? IF yes what is the use of such constructors or destructors.....in the sense where can these be implemented in a system................. I have...
3
by: Nuno Barros | last post by:
Cn someone tell me if when i call the destructor of a derivated class, the destructor of the base class is called implicitly? Or shall i call the destructor by myself? Thanks in advance ...
12
by: Ross Boylan | last post by:
I am trying to understand under what circumstances destructors get called with std::vector. I have an application in which I will put real objects, not just pointers, in the vector. 1. The...
8
by: johny smith | last post by:
If I have a simple class with say a couple of integers only is there any need for me to provide a destructor? thanks!
7
by: qazmlp | last post by:
When a member function is declared as virtual in the base class, the derived class versions of it are always treated as virtual. I am just wondering, why the same concept was not used for the...
26
by: Michi Henning | last post by:
I've been having problem with destructors in the context of having ported C# code developed under .NET to Mono. What happens is that, on a dual-CPU machine, various parts of the code crash randomly...
8
by: Edward Diener | last post by:
I have a __value class which uses some legacy C++ code. So I wrapped the legacy C++ code in another __nogc class and have a pointer to that class as a member of my __value class. When the __value...
3
by: alex.gman | last post by:
If I have code like this int f() { // ... stuff ... g(); if(x > 0) return (x+4); // ... more stuff ... always_call(z); return y; }
6
by: mlw | last post by:
Could someone explain why there is no destructor in Java classes? There are many times you need to be called WHEN an object goes out of scope and not when it will eventally be freed.
6
by: Jeff Newman | last post by:
Hello, Could anyone explain to me why the following class's destructor shows up as having multiple branches? (At least as judged by gcov 4.1.2 when compiled with gcc 4.1.2 ): struct blah {...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.