Just wondering,
Is it possible for an instance of a class to unset itself?
can I do "unset($thi s)" or "unset(&$th is)"
regards,
Lieven http://eye.cc php newsgroups 7 5234
Don't be silly. The execution path is sequential, so after a command which
does not involve a jump is executed the next instruction to be executed will
be the very next instruction in the same object method. If you have just
erased the object that contains the next instruction what do you think will
happen? How is the PHP processor supposed to know where to go?
--
Tony Marston http://www.tonymarston.net
"lievendp" <li******@pando ra-dot-be.no-spam.invalid> wrote in message
news:dt******** ***@news3.infoa ve.net... Just wondering,
Is it possible for an instance of a class to unset itself? can I do "unset($thi s)" or "unset(&$th is)"
regards, Lieven http://eye.cc php newsgroups
No, unset($this) will only remove $this from variable space of the
current function scope. The object will remain in the caller scope.
You can do a $this = null to overwrite the object however.
Tony Marston said the following on 21/02/2006 09:46: Don't be silly. The execution path is sequential, so after a command which does not involve a jump is executed the next instruction to be executed will be the very next instruction in the same object method. If you have just erased the object that contains the next instruction what do you think will happen? How is the PHP processor supposed to know where to go?
I dunno about PHP, but the equivalent is perfectly possible in C++, i.e.
you can call delete on this (assuming it's a heap-based object).
The object and its method code are not one and the same thing. Deleting
an object doesn't mean that the code disappears...
However, like I said, I don't know what PHP allows you to do or not.
--
Oli
"Oli Filth" <ca***@olifilth .co.uk> wrote in message
news:0F******** ***********@new sfe6-win.ntli.net... Tony Marston said the following on 21/02/2006 09:46: Don't be silly. The execution path is sequential, so after a command which does not involve a jump is executed the next instruction to be executed will be the very next instruction in the same object method. If you have just erased the object that contains the next instruction what do you think will happen? How is the PHP processor supposed to know where to go?
I dunno about PHP, but the equivalent is perfectly possible in C++, i.e. you can call delete on this (assuming it's a heap-based object).
The object and its method code are not one and the same thing. Deleting an object doesn't mean that the code disappears...
An object is comprised of methods (code) and properties (variables). If you
delete/unset an object then both disappear as all their reference points no
longer exist. The code may still exist in the class definition, but the
object, which contains a copy of that code in memory, does not, so how can
it continue executing any of that code?
Deleting an object while you are still inside it is like blowing up a house
when you are still inside - not a good idea!
Tony Marston said the following on 23/02/2006 10:02: "Oli Filth" <ca***@olifilth .co.uk> wrote in message news:0F******** ***********@new sfe6-win.ntli.net... Tony Marston said the following on 21/02/2006 09:46: Don't be silly. The execution path is sequential, so after a command which does not involve a jump is executed the next instruction to be executed will be the very next instruction in the same object method. If you have just erased the object that contains the next instruction what do you think will happen? How is the PHP processor supposed to know where to go? I dunno about PHP, but the equivalent is perfectly possible in C++, i.e. you can call delete on this (assuming it's a heap-based object).
The object and its method code are not one and the same thing. Deleting an object doesn't mean that the code disappears...
An object is comprised of methods (code) and properties (variables). If you delete/unset an object then both disappear as all their reference points no longer exist. The code may still exist in the class definition, but the object, which contains a copy of that code in memory, does not, so how can it continue executing any of that code?
Well, in C++, objects most definitely don't keep a copy of the method
code in memory. When you call something like obj.Func(var); in C++
(assuming obj is an instance of class Foo), the compiler actually
translates that to something like:
__Foo__Func(&ob j, var);
with the method actually just equivalent to a normal global function,
internally defined as something like:
void __Foo__Func(str uct Foo *this, int var)
{
...
}
and Foo internally defined as:
struct Foo
{
/* member variables of Foo */
}
Calling delete this; just deallocates the storage space set aside for
the Foo struct. Nothing at all happens to the code.
I'd like to think that something similar occurs in PHP, as making a
"copy" of the code every time you create an object would be a waste of
time and memory.
Deleting an object while you are still inside it is like blowing up a house when you are still inside - not a good idea!
Going back to C++, use of "delete this" is quite a common practice in
smart-pointer/reference-counting classes, or objects designed not to
have any other references to them.
--
Oli
PHP is not C++, so expecting the same behaviour from two different languages
is just being too optimistic. It is not wise to delete an object while you
are still inside it, nor is it wise to overwrite it with something else
while you are still inside it. Why? Because it buggers up any references to
the original object which may still exist in other places.
--
Tony Marston http://www.tonymarston.net
"Oli Filth" <ca***@olifilth .co.uk> wrote in message
news:kA******** ***********@new sfe5-gui.ntli.net... Tony Marston said the following on 23/02/2006 10:02: "Oli Filth" <ca***@olifilth .co.uk> wrote in message news:0F******** ***********@new sfe6-win.ntli.net... Tony Marston said the following on 21/02/2006 09:46: Don't be silly. The execution path is sequential, so after a command which does not involve a jump is executed the next instruction to be executed will be the very next instruction in the same object method. If you have just erased the object that contains the next instruction what do you think will happen? How is the PHP processor supposed to know where to go?
I dunno about PHP, but the equivalent is perfectly possible in C++, i.e. you can call delete on this (assuming it's a heap-based object).
The object and its method code are not one and the same thing. Deleting an object doesn't mean that the code disappears...
An object is comprised of methods (code) and properties (variables). If you delete/unset an object then both disappear as all their reference points no longer exist. The code may still exist in the class definition, but the object, which contains a copy of that code in memory, does not, so how can it continue executing any of that code?
Well, in C++, objects most definitely don't keep a copy of the method code in memory. When you call something like obj.Func(var); in C++ (assuming obj is an instance of class Foo), the compiler actually translates that to something like:
__Foo__Func(&ob j, var);
with the method actually just equivalent to a normal global function, internally defined as something like:
void __Foo__Func(str uct Foo *this, int var) { ... }
and Foo internally defined as:
struct Foo { /* member variables of Foo */ }
Calling delete this; just deallocates the storage space set aside for the Foo struct. Nothing at all happens to the code.
I'd like to think that something similar occurs in PHP, as making a "copy" of the code every time you create an object would be a waste of time and memory.
Deleting an object while you are still inside it is like blowing up a house when you are still inside - not a good idea!
Going back to C++, use of "delete this" is quite a common practice in smart-pointer/reference-counting classes, or objects designed not to have any other references to them.
-- Oli
Tony Marston said the following on 23/02/2006 23:49: PHP is not C++, so expecting the same behaviour from two different languages is just being too optimistic.
I'm not; I was just disputing the assertion that an object is a
collection of code and variables.
It is not wise to delete an object while you are still inside it, nor is it wise to overwrite it with something else while you are still inside it. Why? Because it buggers up any references to the original object which may still exist in other places.
In most situations, yes. But the whole point of having an object delete
itself (in OO languages in general) is in situations where there are
intentionally no external pointers/references to it. In PHP, I can't
see how such a situation could exist, though.
The point is moot, however, because the language doesn't allow it...
--
Oli This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert Schott |
last post by:
Hi .. this is for sure the 1k question on fopen but maybe can someone
tell me this weird staff
if i'm writing:
$H = fopen($value,"r");
while(!feof($H))
{
$string = fgets($H,1024);
....
.... blabla
|
by: sathia |
last post by:
Hi, I have this table:
CREATE TABLE `osservatorio` (
`id` int(10) unsigned NOT NULL auto_increment,
`testo` varchar(255) NOT NULL default '',
`parent` int(11) default NULL,
`allegato` varchar(255) default NULL,
`descrizione` varchar(255) default NULL,
`online` enum('true','false') NOT NULL default 'true',
PRIMARY KEY (`id`),
|
by: Ron Guerin |
last post by:
The New York Linux User's Group invites you to a special presentation
by Alex Martelli of Google, on the Python Object Model. This
presentation will be held at P.J. Clarke's Sidecar, rather than our
usual location, and Google is picking up the tab for an hour and a half
of open bar and food. Additionally, if you're looking for a job as a
Python developer, bring your resume.
Please RSVP at http://rsvp.nylug.org to attend, as seating is...
|
by: Ron Guerin |
last post by:
(date and time inadvertently omitted last time. sorry!)
The New York Linux User's Group invites you to a special presentation
by Alex Martelli of Google, on the Python Object Model. This
presentation will be held at P.J. Clarke's Sidecar, rather than our
usual location, and Google is picking up the tab for an hour and a half
of open bar and food. Additionally, if you're looking for a job as a
Python developer, bring your resume.
...
|
by: Bibby |
last post by:
Hi, I'm interested in getting started in the programming world. I've dabbled
in C, C++ and VB6. Which would be the best language to focus my attention to
regarding the following considerations:
Hireability
Portability
Flexibility
The likely candidates seem to be Java, VB.Net, C, C++, C#.
| |
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted
********************************************************
For this teeny job, please refer to:
http://feeds.reddit.com/feed/8fu/?o=25
|
by: Joe |
last post by:
I am just starting to use Object Oriented PHP coding, and I am seeing
quite often the following (this example taken from a wiki):
$wakka =& new Wakka($wakkaConfig);
What exactly is the =&, and why is it different from = ?
|
by: jeddiki |
last post by:
Hi,
As I am in Turkey at present, I can not see vidoes on
youtube. So I have tried a few proxies but keep finding them slow or
not working.
So I have installed myphpProxy on my server under the
domain name www.blog-start.com
Unfortuantely it is not not working correctly
|
by: mattehz |
last post by:
Hey there,
I am trying to upload old source files and came across these errors:
Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59
Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
|
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: 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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |