Reply to Re: How can I access other scopes (NOT global)

Your name:

Reply:


Posted by Michael Fesser on 01/07/08 18:32

..oO(giblfiz)

>I was hoping that someone on the group might have an idea of how to
>access scopes (or symbol tables) other than the one you are currently
>running in. (and no I don't mean global)
>
>In particular, I'm trying to use register_tick_function, and have the
>function that it calls be able to get at variables in the scope of
>what (otherwise) would currently be executing. Unfortunately the scope
>of the function called by register_tick_function seems to be it's
>own.

Correct. That's how it works in almost every language.

>An example in code:
><?php
>
>function a(){
> $my_a = "mystery_value";
> b();
>}
>
>function b(){
> echo($my_a); //doesn't work
>}
>
>a();
>?>
>
>So I'm trying to figure out how to get at $my_a, none of the obvious
>(to me) solutions are viable, I can't simply pass $my_a to b because b
>is being called by a tick. I can't store $my_a in the globals because
>I don't get to modify any of the code in a(). (I would be more than
>happy with a solution where all scope variables were pushed into
>global, but I can't think of a way to do this.

What about OOP? Putting a() and b() into a class would give you kind of
a common namespace for both.

And what about a() - are you not able to modify it or do you just don't
want to modify it? If the code of a() is "fixed", how is this entire
thing supposed to work? Without some ugly hacking it would be impossible
in almost every language. Maybe you can post some more details about
what this whole thing is about and what you're trying to accomplish.

Micha

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация