Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Reflection API doesn't provide list of Nested Functions

 
   Database Forums (Home) -> PHP RSS
Next:  add content to word or pdf file using php  
Author Message
rehevkor5

External


Since: Nov 20, 2006
Posts: 2



(Msg. 1) Posted: Mon Nov 20, 2006 8:38 pm
Post subject: Reflection API doesn't provide list of Nested Functions
Archived from groups: comp>lang>php (more info?)

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

 >> Stay informed about: Reflection API doesn't provide list of Nested Functions 
Back to top
Login to vote
Moot

External


Since: Oct 18, 2006
Posts: 6



(Msg. 2) Posted: Tue Nov 21, 2006 5:14 am
Post subject: Re: Reflection API doesn't provide list of Nested Functions [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.

 >> Stay informed about: Reflection API doesn't provide list of Nested Functions 
Back to top
Login to vote
rehevkor5

External


Since: Nov 20, 2006
Posts: 2



(Msg. 3) Posted: Tue Nov 21, 2006 3:36 pm
Post subject: Re: Reflection API doesn't provide list of Nested Functions [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.
 >> Stay informed about: Reflection API doesn't provide list of Nested Functions 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
a nested array in a $_POST variable? - Hello all - Is there a way to get a nested array in a $_POST variable? I have a form where there are several questions, each one corresponding to a database row. On submission of the form, I loop through the $_POST array, and update the database..

Nested foreach loop over same array - I'm using next snippet: $somearray = array(...); foreach($somearray as $item1) { foreach($item1 as $item2) { // ... do something ... } } ....and I'm getting next error: Invalid argument supplied for foreach() on second foreach....

&$ in functions - Hi guys, at present Iīm editing some old scripts from a colleague from mine. In one function I fund something I didnīt understand. The function looks like: function foobar(&$val, $key = ' ') { ... } Could anyone tell me what the &$ stands f...

Are there static functions in PHP? - I have two files which implement functionality in many of my web pages. Each file uses a function named "parseArguments()" that's critical for each of the two files. I often include both files into one webpage, which results in a name clash f...

PHP Image functions -- help - Hello, Could anyone throw some light on the following questions, please? 1) How can I add a hyperlink to an image file generated using GD library? For eg., I'm using ImageString(...) function to add text to a JPEG image. I want to make that text an..
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]