473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reflection API doesn't provide list of Nested Functions

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

Nov 21 '06 #1
2 1458
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.

Nov 21 '06 #2
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.

Nov 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
2
by: Robert W. | last post by:
I'm trying to write a utility that will use Reflection to examine any data model I pass it and correctly map out this model into a tree structure. When I say "any" , in fact there will only be 3...
8
by: Rlrcstr | last post by:
If I have some code behind a form and I want to be able to pass an object to it... any of several user defined classes that I have... and then display the values in the member variables of the...
9
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure...
1
by: mlaw40 | last post by:
I am building a CMS driven website in php and I have a list of terms that for each page content I need to search for and replace with the following code: <a href=""></a> The problem I have is...
7
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
Say I have a class that has a generics List as follows: public List<MyClassmyClassList = new List<MyClass>(); and I want to create another class which tries to add an element of MyClass to...
6
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am slightly familiar with reflection but have never done the following I know how to find a class and call but I haven't done the following The Method return a List of Another Class And...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.