473,396 Members | 1,871 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,396 software developers and data experts.

delete an object ?

Hi to all ;)

I use OOP with PHP4 and i don't understand something.

I have 2 classes VISIT & PLANNING like that:

class clVISIT {
var $when;
var $where;

//constructor
function clVISIT($_when,$_where) {
$this->when = $_when;
$this->where = $_where;
}
}

class clPLANNING {
var $who;
var $visit = array();

//constructor
function ClPLANNING($_who) {
$this->who = $_who;
for ($i=0;$i<10;$i++) { $visit = new clVISIT("foo".$i , "foobar".$i ) ; }
}

}

Ok, in the last constructor, we can see that i create new clVISIT
object. My question is: how can i delete some of them in the same
constructor ? is there a word like "new" but to delete ?

regards,

f.
Jul 17 '05 #1
3 5142
First, if you're trying to do what I think you are, write:

{ $visit[] = new clVISIT("foo".$i , "foobar".$i ) ; }

Note the square brackets after $visit.

To delete an element from an array, just use unset. For instance, to
remove $visit[5], just write unset($visit[5]). This won't re-index the
array -- you'll just have buckets with null values. To re-index it in
a continious way, use:

$visit = array_merge($visit);

However, I'm wondering why you would create them in the first place if
you just intended to delete them...unless of course there's some other
things you do first that you haven't included in the example.

Jul 17 '05 #2
Hi and thanx a lot ;)
However, I'm wondering why you would create them in the first place if
you just intended to delete them...unless of course there's some other
things you do first that you haven't included in the example.

Right. I didn't write some lines to make the example clearer.

regards,

f.
Jul 17 '05 #3
"Fabrice Régnier" <re*********@free.fr> wrote in message
news:42***********************@news.free.fr...
Ok, in the last constructor, we can see that i create new clVISIT
object. My question is: how can i delete some of them in the same
constructor ? is there a word like "new" but to delete ?

regards,


There is no concept of delete or destructor in PHP 4. PHP will delete an
object where it's no longer needed and (sometimes) free up the memory used
for it. You can reclaim memory (sometimes) by unsetting a variable but
there's no guarantee. Because PHP is used primarily for handling web
requests, it likes to free memory either after a script has finished and
(sometimes) not freeing it at all.

OOP in general should be used sparingly in PHP 4, only when there's a
clearly benefit of doing so. It is a weakness of the language. If you insist
on coding to the weakness of a language, you will only come to grief.
Jul 17 '05 #4

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

Similar topics

52
by: Newsnet Customer | last post by:
Hi, Statement 1: "A dynamically created local object will call it's destructor method when it goes out of scope when a procedure returms" Agree. Statement 2: "A dynamically created object...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
11
by: Squid Seven | last post by:
I create a pointer to an item: CardSession *cardSession; Then, later, I use new to create an instance of the item and assign it to that pointer: cardSession = new CardSession(); In...
5
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious...
5
by: tom | last post by:
Hi, I'm overriding my operator new and operator delete for two classes, one inherited from the other, so I can use my own memory pool. A simplified version of what I have is below: class...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
9
by: Money | last post by:
If I allocate memory like this int *ptr = new int; Can I apply delete ptr; instead of delete ptr; since I am only allocating memory for 1 integer.
15
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

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.