# Reflection API RFC

- Thread: https://externals.io/message/475
- Original archive: https://news-web.php.net/php.internals/475
- Started by Andrei Zmievski on 2003-03-29T20:37:30+00:00
- Messages: 11
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #475 — Andrei Zmievski — 2003-03-29T20:37:30+00:00

URL: https://externals.io/message/475#475

I have the first draft of PHP 5 reflection API ready. You can find it
at:

  http://www.gravitonic.com/software/php/reflection.txt

Comments and suggestions are appreciated.

-Andrei                                       http://www.gravitonic.com/

"Beware of bugs in the above code; I have only proved it correct,
 not tried it." -- Donald Knuth

---

## #479 — marcus.boerger@t-online.de — 2003-03-29T21:00:33+00:00

URL: https://externals.io/message/475#479 · In reply to: #475

At 21:37 29.03.2003, Andrei Zmievski wrote:
>I have the first draft of PHP 5 reflection API ready. You can find it
>at:
>
>   http://www.gravitonic.com/software/php/reflection.txt
>
>Comments and suggestions are appreciated.


What about doing it with some interfaces?

marcus

---

## #481 — Andrei Zmievski — 2003-03-29T21:09:40+00:00

URL: https://externals.io/message/475#481 · In reply to: #479

> > […]
> 
> 
> What about doing it with some interfaces?

Why?

-Andrei                                       http://www.gravitonic.com/
* Software never has bugs. It just develops random features. *

---

## #485 — Timm Friebe — 2003-03-29T21:28:00+00:00

URL: https://externals.io/message/475#485 · In reply to: #475

> I have the first draft of PHP 5 reflection API ready. You can find it
> at:
> 
>   http://www.gravitonic.com/software/php/reflection.txt
> 
> Comments and suggestions are appreciated.

* ClassType::getMethods([int flags]);

I assume flags is a bitfield of private, public, protected, final 
and so on, defaulting to all of them?

- Timm

---

## #486 — Andrei Zmievski — 2003-03-29T21:34:28+00:00

URL: https://externals.io/message/475#486 · In reply to: #485

> > […]
> 
> * ClassType::getMethods([int flags]);
> 
> I assume flags is a bitfield of private, public, protected, final 
> and so on, defaulting to all of them?

Something like that. I haven't finalized what kind of method searching
will be available. Perhaps one of the flags will be REGEXP with a
optional argument specifying the regexp to match method name against.

-Andrei                                       http://www.gravitonic.com/

"Beware of bugs in the above code; I have only proved it correct,
 not tried it." -- Donald Knuth

---

## #491 — Alan Knowles — 2003-03-30T02:03:08+00:00

URL: https://externals.io/message/475#491 · In reply to: #475

A few more ideas for it:)

-  If you stored token start/end then you would be able to do getSource 
for function/method/class.. etc.. (which can do a load file/tokenizer 
and return implode('',array_range(starttoken,endtoken)
- and add the generic methods
loadTokens(); and freeTokens(); so that memory can be managed reasonably 
for them..
* it may also be better to store the token of the doc comment - On some 
of the pear classes the comment code is larger than the PHP code, and 
would be quite an overhead... - just make it throw an exception if you 
forgot to load the tokens for it..

- there appears to be no arguments array for methods/functions

- not sure if extendsClass(), would be implemented by Implements?, and 
theres no getExtendsArray(), to return the tree of extends

- constructors: -
$classdetails = new ClassType('myclass');
$classdetails = new ClassType($this);
rather than
$classdetails = ClassType::fromName('myclass')
$classdetails = ClassType::fromInstance('myclass')

- I still think it would be nice to implement some of them as variables 
so that
print_r($classdetails); would display some cute output...




btw - It would also be nice to have unloadclass - so
a) the codedoc generators - could load and free classes.
b) php-gtk could reload modules rather than having to restart each time 
to test code..

Regards
Alan


Andrei Zmievski wrote:

>I have the first draft of PHP 5 reflection API ready. You can find it
>at:
>
>  http://www.gravitonic.com/software/php/reflection.txt
>
>Comments and suggestions are appreciated.
>
>-Andrei                                       http://www.gravitonic.com/
>
>"Beware of bugs in the above code; I have only proved it correct,
> not tried it." -- Donald Knuth

---

## #508 — Andi Gutmans — 2003-03-30T17:44:15+00:00

URL: https://externals.io/message/475#508 · In reply to: #475

At 03:37 PM 3/29/2003 -0500, Andrei Zmievski wrote:
>I have the first draft of PHP 5 reflection API ready. You can find it
>at:
>
>   http://www.gravitonic.com/software/php/reflection.txt
>
>Comments and suggestions are appreciated.

By the way, I might have missed it,but maybe we should have a way to check 
if the method was defined in the specific class or if it is inherited.

Andi

---

## #510 — Jon Parise — 2003-03-30T19:53:55+00:00

URL: https://externals.io/message/475#510 · In reply to: #475

> I have the first draft of PHP 5 reflection API ready. You can find it
> at:
> 
>   http://www.gravitonic.com/software/php/reflection.txt
> 
> Comments and suggestions are appreciated.
 
It would be cool if there was a way to get the (defined) set of
parameters for a function / method.  I'm going to assume that, because
it's not included in your proposal, it's not currently possible given
the current model, though.

-- 
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)

---

## #514 — Andrei Zmievski — 2003-03-30T20:49:36+00:00

URL: https://externals.io/message/475#514 · In reply to: #510

> It would be cool if there was a way to get the (defined) set of
> parameters for a function / method.  I'm going to assume that, because
> it's not included in your proposal, it's not currently possible given
> the current model, though.

Right. The engine would need to be modified in order to keep track of
that.

-Andrei                                       http://www.gravitonic.com/

"Everything should be made as simple
as possible, but not simpler."
                  -- Albert Einstein

---

## #554 — Andrei Zmievski — 2003-03-31T20:52:21+00:00

URL: https://externals.io/message/475#554 · In reply to: #491

> -  If you stored token start/end then you would be able to do getSource 
> for function/method/class.. etc.. (which can do a load file/tokenizer 
> and return implode('',array_range(starttoken,endtoken)

Keeping track of the tokens this way would require quite some code, I
think.

> * it may also be better to store the token of the doc comment - On some 
> of the pear classes the comment code is larger than the PHP code, and 
> would be quite an overhead... - just make it throw an exception if you 
> forgot to load the tokens for it..

Hmm, I see the point, but is that really a problem? If a lot of people
are worried about the overhead of storing doc comments, we could perhaps
store only the starting/ending line of the comment and let the other
tools extract them. But it means that the tools have to have access to
the original source file - not really possible with 3rd party software
distributed under an encoder, for example.

> - there appears to be no arguments array for methods/functions

No really good way of doing it with the current architecture. I defer to
Andi/Zeev to see if it's possible to capture the declared parameters
somehow..
 
> - not sure if extendsClass(), would be implemented by Implements?, and 
> theres no getExtendsArray(), to return the tree of extends

What would extendsClass() do?

> - constructors: -
> $classdetails = new ClassType('myclass');
> $classdetails = new ClassType($this);
> rather than
> $classdetails = ClassType::fromName('myclass')
> $classdetails = ClassType::fromInstance('myclass')

I'd rather avoid overloading. And in this case, these methods are
basically factories.
 
> - I still think it would be nice to implement some of them as variables 
> so that
> print_r($classdetails); would display some cute output...

We could always have toString() method for each one..

> btw - It would also be nice to have unloadclass - so
> a) the codedoc generators - could load and free classes.
> b) php-gtk could reload modules rather than having to restart each time 
> to test code..

What do you mean by unloadclass?

-Andrei                                       http://www.gravitonic.com/

"This isn't right. This isn't even wrong."
           -- Wolfgang Pauli

---

## #562 — Sebastian Bergmann — 2003-04-01T07:07:20+00:00

URL: https://externals.io/message/475#562 · In reply to: #554

Andrei Zmievski wrote:
> What do you mean by unloadclass?

  I think what the name suggests: unload a class, ie. undeclare it.

-- 
  Sebastian Bergmann
  http://sebastian-bergmann.de/                 http://phpOpenTracker.de/

  Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/
