# Work on reflection API

- Thread: https://externals.io/message/3093
- Original archive: https://news-web.php.net/php.internals/3093
- Started by Timm Friebe on 2003-07-01T18:27:28+00:00
- Messages: 4
- 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

---

## #3093 — Timm Friebe — 2003-07-01T18:27:28+00:00

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

Hello,
I went ahead and spent some time on the new reflection API. A patch (778
lines:)) and a demo script are attached.

What has changed:

---------------------------------------------------------------------

- Added documentation for each and every function (using the style
  used in ext/*/*.c), e.g.:

  /* {{{ proto Reflection_Class[] Reflection_Class::getInterfaces()
     Returns an array of interfaces this class implements */

- Replaced duplicated code with macros or functions

- Added protection against static calls to the Reflection_* classes'
  functions (resulting in fatal errors if you try to do so).

- Made Reflection_Class::getInterfaces return an empty array instead
  of `FALSE` in case the class does not implement any interfaces

- Made Reflection_Function::getStaticVariables return an empty array
  instead of `FALSE` in case the function does not have any static
  variables.

- Made use of the ZEND_DO_THROW macro in the constructors (see
  previous mail to engine2@ including a patch to zend_API.h)

- Added Reflection_Class::isFinal

- Added Reflection_Class::isAbstract

- Added Reflection_Class::newInstance. This method takes a variable
  amount of arguments and passes them to the object's constructor
  if there is one.

- Added Reflection_Class::isInstance

---------------------------------------------------------------------

I couldn't figure out how to remove the following memleaks which
occur when the reflection_class_factory is called:

  /usr/home/thekid/devel/php/php/Zend/zend_reflection_api.c(296) :
  Freeing 0x08371D24 (7 bytes), script=reflection.php
  Last leak repeated 1 time
  /usr/home/thekid/devel/php/php/Zend/zend_reflection_api.c(295) : 
  Freeing 0x08371CE4 (16 bytes), script=reflection.php
  Last leak repeated 1 time

-- 
Timm

---

## #3094 — George Schlossnagle — 2003-07-01T18:44:37+00:00

URL: https://externals.io/message/3093#3094 · In reply to: #3093

> - Made use of the ZEND_DO_THROW macro in the constructors (see
>   previous mail to engine2@ including a patch to zend_API.h)

I privatized this for the moment until your other patch is accepted or 
what have you.  Otherwise looks great.  Committing.
>
> - Added Reflection_Class::newInstance. This method takes a variable
>   amount of arguments and passes them to the object's constructor
>   if there is one.

I don't think this works correctly for builtin classes that need to do 
their own allocation.  I'll poke some more, or you can convince me I'm 
wrong.

Otherwise everything looks cool.

---

## #3121 — Timm Friebe — 2003-07-01T21:27:08+00:00

URL: https://externals.io/message/3093#3121 · In reply to: #3093

> Hello,
> I went ahead and spent some time on the new reflection API. A patch (778
> lines:)) and a demo script are attached.

More to come:
---------------------------------------------------------------------
- Added some necessary efree()'s before an exception is thrown (as 
  ZEND_DO_THROW returns from the function immediately.

- Added Reflection_Method class
  TBI: getDeclaringClass()

- Added Reflection_Class::getModifiers which returns a long 
  consisting of the bitmask of modifiers which are registered
  as constants with the following names:

  STATIC
  ABSTRACT
  FINAL
  INTERFACE
  ABSTRACT_CLASS
  FINAL_CLASS
  PUBLIC
  PROTECTED
  PRIVATE
  PPP_MASK
  CHANGED
  IMPLICIT_PUBLIC

  TBDiscussed: Would something like
    $modifiers= array('public', 'static')
  be cooler? Currently, one would be checking with
    $modifiers & STATIC
  etc.

- Added Reflection_Class::getConstructor

- Added Reflection_Class::getMethod(string name)

- Added Reflection_Class::getMethods()

---------------------------------------------------------------------

> I couldn't figure out how to remove the following memleaks which
> occur when the reflection_class_factory is called:

I found and eliminated them:)

Btw, the Reflection_Method->invoke() will not work without the patch to
zend_execute_API.c in my previous mail to engine2@.

- Timm

---

## #3194 — Andrei Zmievski — 2003-07-03T13:25:02+00:00

URL: https://externals.io/message/3093#3194 · In reply to: #3121

> - Added Reflection_Class::getModifiers which returns a long 
>   consisting of the bitmask of modifiers which are registered
>   as constants with the following names:
> 
>   STATIC
>   ABSTRACT
>   FINAL
>   INTERFACE
>   ABSTRACT_CLASS
>   FINAL_CLASS
>   PUBLIC
>   PROTECTED
>   PRIVATE
>   PPP_MASK
>   CHANGED
>   IMPLICIT_PUBLIC

Should these be grouped somehow? PPP has a separate domain than
ABSTRACT_CLASS and FINAL_CLASS, for example.

>   TBDiscussed: Would something like
>     $modifiers= array('public', 'static')
>   be cooler? Currently, one would be checking with
>     $modifiers & STATIC

No, I'd prefer a bitmask rather than an array like that.

-Andrei
* There is no knowledge that is not power. -- Ralph Waldo Emerson *
