You are here: Re: Reflection API doesn't provide list of Nested Functions « PHP Programming Language « IT news, forums, messages
Re: Reflection API doesn't provide list of Nested Functions

Posted by rehevkor5 on 11/21/06 23:36

Moot wrote:
> rehevkor5 wrote:
> > I am trying to use the reflection API in PHP 5 to execute the functions
> > in a class which looks like:
> >
> > class Meow
> > {
> > function context()
> > {
> > function a()
> > {
> > }
> >
> > function b()
> > {
> > }
> > }
> > }
> >
> >
> > I can run the following code to get the methods inside the Meow class,
> > but have no way of getting the functions inside those methods. In this
> > case, I specifically cannot get to a() and b() even though I know about
> > context().
> >
> > $class = new ReflectionClass('Meow');
> >
> > $methods = $class->getMethods();
> >
> > foreach($methods as $method)
> > {
> > //get functions inside $method (how??)
> > }
> >
> > Is there a way to do this? If not, I'm thinking of submitting a bug
> > report to PHP.net
>
> Look at this page from the manual, specifically example 17-3.
> http://us3.php.net/manual/en/language.functions.php
>
> It seems as if the inner "bar" function does not exist until the
> function "foo" is called once. I'm not completely sure, but it would
> seem to me to be that functions a and b are not in the reflection API
> yet because as far as PHP knows, they don't exist.
>
> I'm curious, though, as to why you have structured the class this way.
> With only the code you provided to go on, I'd guess you're trying to
> change the logic for the a and b functions depending on which context
> function you call. A much cleaner way to do that would be to use the
> Factory pattern and subclass out each context you want to have
> available.

I bet you're right, good call. Now it's a question of how conscious a
design decision that was. If I submit a bug report based on it, they
may mark it "bogus" and say it behaves as expected.

As for my code & why it's structured that way, it's just something I'm
fiddling with to imitate the RSpec syntax. Since that's written in
Ruby, it has some language constructs that don't really exist in PHP.
I'm coming to the conclusion that it won't be possible to directly
imitate RSpec. This is all just preliminary though. I thought I'd
give it a whack. If my code did what you said, subclassing would
indeed be much better.

 

Navigation:

[Reply to this 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

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