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 =---- 5 1350
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("some file","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
"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 =----
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
Janwillem Borleffs schrieb: Joachim Weiß wrote:
//destructor // watch the underscore function _Something( fclose($thi s->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("some file","r");
}
function __destruct() {
fclose($this->fp);
}
}
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******@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 an idea that we can have private constructors and destructors
but am not able to find a situation where they can be used...
Regards
RVG
rajeshgarg@opussoft.com
|
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
Nuno Barros
|
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 standard says that empty() has constant complexity. If it actually
called the destructor for each object, it seems to me it would have
linear complexity. Does empty() call the destructor for each object in the
container? If yes, why is it described...
|
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!
|
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
destructors.
What I am expecting is, if the destructor is declared as virtual in
base, the destructors of all its derived classes also should be
virtual always.
What exactly is the reason for not having it so?
| |
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 (and rarely). This always happens during
process shutdown, after some thread has called System.Environment.Exit(). Clearly,
some sort of race condition.
Note that what follows only applies to destructors that are called when the process
shuts...
|
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 class is created, I
dynamically allocate an object of the class with the legacy C++ code.
However because the __value class has no destructor, I can never release
that allocated memory. Why does a __value class allow no destructor ?
Without it I...
|
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;
}
|
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.
|
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
{
blah();
virtual ~blah();
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |