Well in general if you have an object and leave the function which instantiated it, it'll be destroyed (unless you hold a reference to it from some global, in which case you probably don't want it to be destroyed). I don't think it has to be more fine-grained than that.

At 05:50 AM 8/1/2004 +0200, Michael Walter wrote:
Andi Gutmans wrote:
I'm starting to like goto more and more :)
Good good :)

At least it's a simple concept as opposed to using/scoped which make me dizzy.
Hehe, I think scoped could be pretty useful, though.

Cheers,
Michael

At 03:24 AM 8/1/2004 +0200, Michael Walter wrote:

Paul G wrote:

----- Original Message ----- From: "Michael Walter" <[EMAIL PROTECTED]>
To: "Paul G" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Saturday, July 31, 2004 1:59 PM
Subject: Re: [PHP-DEV] GOTO operator

--- snip ---

presumably, you see the need in C because it's the cleanest way to

free()

all you've malloc()ed along the way, regardless of where you've errored

out.

in PHP, you've got gc, which (again presumably) makes you think we don't
need goto. i say that we alloc() stuff quite often, but it may be

objects,

resources, what have you instead of chunks.


It's interesting that there is the desire for a low-level construct such
as "goto" in order to implement scoped deallocation/deconstruction. I
suppose something like C#' using() statement might help you in this
case, although suggesting it will surely lead to another discussion ;)


actually, alloc/dealloc was just used as an example. it could be anything -
rollback, closing sockets, pretty much any sort of 'undoing' that you need
to do to make it look like nothing ever happened ;)

Of course, what makes you think C#'s using() is restricted to deallocation?

> what you are suggesting

is similar to the hack i'm using now and referred to in an earlier mail, ie
registering thingers to be 'undone'. while useful for certain things, it's
too verbose for the majority of situations When Done Here(tm).

Actually what I was throwing into the discussion is IMO often the cleaner solution. You encapsulate _both_ construction and destruction logic into the same object, and as a client you just use the using() statement in order to have the language take care about the management.


Another possibility, possibly more concise, would be to introduce a "scoped" keyword (or similar) in the spirit of "global":

  scoped $foo;

might make $foo's destructor be called at the end of the current scope (whether left by a return statement or by an exception).

Note that this only solves one part of the problem which could be summarized as "resource management". I'm not sure about generated code - did someone already post an example where goto might be useful in that case or did I miss that one?

Cheers,
Michael

paul
paul


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to