|
Posted by Moot on 11/21/06 13:14
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.
Navigation:
[Reply to this message]
|