Re: Function returning but continues execution

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2007-01-23 at 03:01 +0100, Jochem Maas wrote:
> Robert Cummings wrote:
> > On Tue, 2007-01-23 at 02:43 +0100, Jochem Maas wrote:
> >> there is no way in hell that [a released version of] php is so borked that it's capable
> >> returning a value from a function and then going on to running code that occurs in the function
> >> after the return statement that returned the value. no way, no how.
> > 
> > Borked for PHP sure... 
> 
> it's the lang I know best, I think you'll agree that it's *highly* unlikely such an
> extreme level of brokeness (as far as php is concerned) would creep into a release version.
> 
> > but there are languages where that semantic is
> > perfectly valid :)
> 
> I would not have thought so but then again my skills and experience are somewhat
> limited in the grand scheme of things.
> 
> you've twanged my interest, please name the language you were thinking of
> when you wrote that last comment :-)

Well, my own BlobbieScript supports a retval keyword that returns a
value to the caller and then continues on as a separate thread. But I
can't take credit for the concept. I spoke with an imp of another MUD
that mentioned it in passing, so I implemented the functionality
realizing it's utility. So I know at least one other language supports
it, and not my own, but I'm not aware of it's name.

Why would you do it? Imagine a function in a game script that is invoked
for a return value, but upon probing for that return value an action is
triggered. Depending on when you want that action to trigger you can
either do it before returning the value or wait until afterwards. Some
languages would have you set up timed event handler (such as
setTimeout() in JavaScript), but why bother if you're already running...
instead just sleep until ready... this delayed action is what follows
the return value and removes the cumbersome nature of setting up an
event handler. The additional advantage of this method is you retain all
the variables of the current calling scope without having to either pass
them along or create a closure with an anonymous function.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux