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
ofFALSEin case the class does not implement any interfaces -
Made Reflection_Function::getStaticVariables return an empty array
instead ofFALSEin 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
- 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.
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_PUBLICTBDiscussed: 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
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 *