On Mon, 2007-03-19 at 13:59 -0700, Stanislav Malyshev wrote:
> > What about just having a function that allows retrieving variables from
> > the parent scope?
> > 
> >     mixed seek_var( $name [, $levels=1, [ $startLevel=0 ] ] )
> 
> How you are going to know where "parent scope" is? It can even be not 
> existing anymore, or can be separated by any number of parameter 
> passing. Remember that the function is defined at compile-time, but 
> invoked at run-time by some other function.

I guess I was primarily thinking in the context of the anonymous
function being defined in your previous example. As such the parent
scope is known (or at least can be expected), unless (unknown to me)
within the internal C code the scope can change other than the hierarchy
one would see visually while writing PHP code. From your example:

 On Sun, 2007-03-18 at 19:06 -0700, Stanislav Malyshev wrote:
>
>    What happens if you do this:
>    $data = array("zoo", "orange", "car", "lemon", "apple");
>    $rev = 1;
>    usort($data, function($a, $b) { return $rev?strcmp($a, $b):!
strcmp($a, 
$b); });
>    var_dump($data); # data is sorted alphabetically
>

We would have:

<?php

$data = array("zoo", "orange", "car", "lemon", "apple");
$rev = 1;
usort($data, function($a, $b) { return seek_var( 'rev' )?strcmp($a,
$b):!strcmp($a, 
$b); });
var_dump($data); # data is sorted alphabetically

?>

Can we not expect that the lexical scope of the $rev is the immediate
parent of the anonymous function at runtime? Obviously this could also
work for normally defined functions if there's an expectation of the
calling environment having some specific variable defined.

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 Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to