summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2008-07-14 09:49:03 +0000
committerDmitry Stogov <dmitry@php.net>2008-07-14 09:49:03 +0000
commitd5ef2f466cb112fd977a71419fa4b67d0aa0a2ac (patch)
tree2f61549b96e8db664a1467f36ce11772600c86a9 /ext/reflection
parentd23342397c14a6efb3e0b1ea20928f81ccc48657 (diff)
downloadphp-git-d5ef2f466cb112fd977a71419fa4b67d0aa0a2ac.tar.gz
Added support for lambda functions and closures
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/php_reflection.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index c027dae308..f99e009830 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -38,6 +38,7 @@
#include "zend_constants.h"
#include "zend_ini.h"
#include "zend_interfaces.h"
+#include "zend_closures.h"
/* Undefine "getParameters" macro defined in "main/php3_compat.h" */
#ifdef getParameters
@@ -1562,6 +1563,20 @@ ZEND_METHOD(reflection_function, getStaticVariables)
}
/* }}} */
+/* {{{ proto public mixed ReflectionFunction::getClosure()
+ Invokes the function */
+ZEND_METHOD(reflection_function, getClosure)
+{
+ reflection_object *intern;
+ zend_function *fptr;
+
+ METHOD_NOTSTATIC_NUMPARAMS(reflection_function_ptr, 0);
+ GET_REFLECTION_OBJECT_PTR(fptr);
+
+ zend_create_closure(return_value, fptr, NULL, NULL TSRMLS_CC);
+}
+/* }}} */
+
/* {{{ proto public mixed ReflectionFunction::invoke(mixed* args)
Invokes the function */
ZEND_METHOD(reflection_function, invoke)
@@ -2290,6 +2305,34 @@ ZEND_METHOD(reflection_method, __toString)
}
/* }}} */
+/* {{{ proto public mixed ReflectionMethod::getClosure([mixed object])
+ Invokes the function */
+ZEND_METHOD(reflection_method, getClosure)
+{
+ reflection_object *intern;
+ zval *obj;
+ zend_function *mptr;
+
+ METHOD_NOTSTATIC(reflection_method_ptr);
+ GET_REFLECTION_OBJECT_PTR(mptr);
+
+ if (mptr->common.fn_flags & ZEND_ACC_STATIC) {
+ zend_create_closure(return_value, mptr, mptr->common.scope, NULL TSRMLS_CC);
+ } else {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
+ return;
+ }
+
+ if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope TSRMLS_CC)) {
+ _DO_THROW("Given object is not an instance of the class this method was declared in");
+ /* Returns from this function */
+ }
+
+ zend_create_closure(return_value, mptr, mptr->common.scope, obj TSRMLS_CC);
+ }
+}
+/* }}} */
+
/* {{{ proto public mixed ReflectionMethod::invoke(mixed object, mixed* args)
Invokes the method. */
ZEND_METHOD(reflection_method, invoke)
@@ -4641,6 +4684,7 @@ static const zend_function_entry reflection_function_functions[] = {
ZEND_ME(reflection_function, __toString, NULL, 0)
ZEND_ME(reflection_function, export, arginfo_reflection_function_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
ZEND_ME(reflection_function, isDisabled, NULL, 0)
+ ZEND_ME(reflection_function, getClosure, NULL, 0)
ZEND_ME(reflection_function, invoke, arginfo_reflection_function_invoke, 0)
ZEND_ME(reflection_function, invokeArgs, arginfo_reflection_function_invokeArgs, 0)
{NULL, NULL, NULL}
@@ -4684,6 +4728,7 @@ static const zend_function_entry reflection_method_functions[] = {
ZEND_ME(reflection_method, isConstructor, NULL, 0)
ZEND_ME(reflection_method, isDestructor, NULL, 0)
ZEND_ME(reflection_method, getModifiers, NULL, 0)
+ ZEND_ME(reflection_method, getClosure, NULL, 0)
ZEND_ME(reflection_method, invoke, arginfo_reflection_method_invoke, 0)
ZEND_ME(reflection_method, invokeArgs, arginfo_reflection_method_invokeArgs, 0)
ZEND_ME(reflection_method, getDeclaringClass, NULL, 0)