PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/reflection - php_reflection.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 2544 2889 88.1 %
Date: 2016-08-24 Functions: 228 240 95.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2016 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Timm Friebe <thekid@thekid.de>                              |
      16             :    |          George Schlossnagle <george@omniti.com>                     |
      17             :    |          Andrei Zmievski <andrei@gravitonic.com>                     |
      18             :    |          Marcus Boerger <helly@php.net>                              |
      19             :    |          Johannes Schlueter <johannes@php.net>                       |
      20             :    +----------------------------------------------------------------------+
      21             : */
      22             : 
      23             : /* $Id: ef04ecdb98589f0690abc65e195f0c391448435c $ */
      24             : 
      25             : #ifdef HAVE_CONFIG_H
      26             : #include "config.h"
      27             : #endif
      28             : 
      29             : #include "php.h"
      30             : #include "php_ini.h"
      31             : #include "php_reflection.h"
      32             : #include "ext/standard/info.h"
      33             : 
      34             : #include "zend.h"
      35             : #include "zend_API.h"
      36             : #include "zend_exceptions.h"
      37             : #include "zend_operators.h"
      38             : #include "zend_constants.h"
      39             : #include "zend_ini.h"
      40             : #include "zend_interfaces.h"
      41             : #include "zend_closures.h"
      42             : #include "zend_generators.h"
      43             : #include "zend_extensions.h"
      44             : #include "zend_builtin_functions.h"
      45             : 
      46             : #define reflection_update_property(object, name, value) do { \
      47             :                 zval member; \
      48             :                 ZVAL_STRINGL(&member, name, sizeof(name)-1); \
      49             :                 zend_std_write_property(object, &member, value, NULL); \
      50             :                 if (Z_REFCOUNTED_P(value)) Z_DELREF_P(value); \
      51             :                 zval_ptr_dtor(&member); \
      52             :         } while (0)
      53             : 
      54             : /* Class entry pointers */
      55             : PHPAPI zend_class_entry *reflector_ptr;
      56             : PHPAPI zend_class_entry *reflection_exception_ptr;
      57             : PHPAPI zend_class_entry *reflection_ptr;
      58             : PHPAPI zend_class_entry *reflection_function_abstract_ptr;
      59             : PHPAPI zend_class_entry *reflection_function_ptr;
      60             : PHPAPI zend_class_entry *reflection_generator_ptr;
      61             : PHPAPI zend_class_entry *reflection_parameter_ptr;
      62             : PHPAPI zend_class_entry *reflection_type_ptr;
      63             : PHPAPI zend_class_entry *reflection_class_ptr;
      64             : PHPAPI zend_class_entry *reflection_object_ptr;
      65             : PHPAPI zend_class_entry *reflection_method_ptr;
      66             : PHPAPI zend_class_entry *reflection_property_ptr;
      67             : PHPAPI zend_class_entry *reflection_class_constant_ptr;
      68             : PHPAPI zend_class_entry *reflection_extension_ptr;
      69             : PHPAPI zend_class_entry *reflection_zend_extension_ptr;
      70             : 
      71             : #if MBO_0
      72             : ZEND_BEGIN_MODULE_GLOBALS(reflection)
      73             :         int dummy;
      74             : ZEND_END_MODULE_GLOBALS(reflection)
      75             : 
      76             : #ifdef ZTS
      77             : # define REFLECTION_G(v) \
      78             :         ZEND_TSRMG(reflection_globals_id, zend_reflection_globals*, v)
      79             : extern int reflection_globals_id;
      80             : #else
      81             : # define REFLECTION_G(v) (reflection_globals.v)
      82             : extern zend_reflection_globals reflectionglobals;
      83             : #endif
      84             : 
      85             : ZEND_DECLARE_MODULE_GLOBALS(reflection)
      86             : #endif /* MBO_0 */
      87             : 
      88             : /* Method macros */
      89             : 
      90             : #define METHOD_NOTSTATIC(ce)                                                                                \
      91             :         if ((Z_TYPE(EX(This)) != IS_OBJECT) || !instanceof_function(Z_OBJCE(EX(This)), ce)) {           \
      92             :                 php_error_docref(NULL, E_ERROR, "%s() cannot be called statically", get_active_function_name());        \
      93             :                 return;                                                                                             \
      94             :         }                                                                                                       \
      95             : 
      96             : /* Exception throwing macro */
      97             : #define _DO_THROW(msg)                                                                                      \
      98             :         zend_throw_exception(reflection_exception_ptr, msg, 0);                                       \
      99             :         return;                                                                                                 \
     100             : 
     101             : #define RETURN_ON_EXCEPTION                                                                                 \
     102             :         if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) {                            \
     103             :                 return;                                                                                             \
     104             :         }
     105             : 
     106             : #define GET_REFLECTION_OBJECT()                                                                                         \
     107             :         intern = Z_REFLECTION_P(getThis());                                                                                     \
     108             :         if (intern->ptr == NULL) {                                                            \
     109             :                 RETURN_ON_EXCEPTION                                                                                 \
     110             :                 zend_throw_error(NULL, "Internal error: Failed to retrieve the reflection object");        \
     111             :                 return;                                                                                             \
     112             :         }                                                                                                       \
     113             : 
     114             : #define GET_REFLECTION_OBJECT_PTR(target)                                                                   \
     115             :         GET_REFLECTION_OBJECT()                                                                                                                                                                 \
     116             :         target = intern->ptr;                                                                                   \
     117             : 
     118             : /* Class constants */
     119             : #define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value)                                        \
     120             :         zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (zend_long)value);
     121             : 
     122             : /* {{{ Smart string functions */
     123             : typedef struct _string {
     124             :         zend_string *buf;
     125             :         size_t alloced;
     126             : } string;
     127             : 
     128        1286 : static void string_init(string *str)
     129             : {
     130        1286 :         str->buf= zend_string_alloc(1024, 0);
     131        1286 :         str->alloced = 1024;
     132        1286 :         ZSTR_VAL(str->buf)[0] = '\0';
     133        1286 :         ZSTR_LEN(str->buf) = 0;
     134        1286 : }
     135             : 
     136       16124 : static string *string_printf(string *str, const char *format, ...)
     137             : {
     138             :         size_t len;
     139             :         va_list arg;
     140             :         char *s_tmp;
     141             : 
     142       16124 :         va_start(arg, format);
     143       16124 :         len = zend_vspprintf(&s_tmp, 0, format, arg);
     144       16124 :         if (len) {
     145       16124 :                 register size_t nlen = (ZSTR_LEN(str->buf) + 1 + len + (1024 - 1)) & ~(1024 - 1);
     146       16124 :                 if (str->alloced < nlen) {
     147         103 :                         size_t old_len = ZSTR_LEN(str->buf);
     148         103 :                         str->alloced = nlen;
     149         206 :                         str->buf = zend_string_extend(str->buf, str->alloced, 0);
     150         103 :                         ZSTR_LEN(str->buf) = old_len;
     151             :                 }
     152       16124 :                 memcpy(ZSTR_VAL(str->buf) + ZSTR_LEN(str->buf), s_tmp, len + 1);
     153       16124 :                 ZSTR_LEN(str->buf) += len;
     154             :         }
     155       16124 :         efree(s_tmp);
     156       16124 :         va_end(arg);
     157       16124 :         return str;
     158             : }
     159             : 
     160        2321 : static string *string_write(string *str, char *buf, size_t len)
     161             : {
     162        2321 :         register size_t nlen = (ZSTR_LEN(str->buf) + 1 + len + (1024 - 1)) & ~(1024 - 1);
     163        2321 :         if (str->alloced < nlen) {
     164          39 :                 size_t old_len = ZSTR_LEN(str->buf);
     165          39 :                 str->alloced = nlen;
     166          78 :                 str->buf = zend_string_extend(str->buf, str->alloced, 0);
     167          39 :                 ZSTR_LEN(str->buf) = old_len;
     168             :         }
     169        2321 :         memcpy(ZSTR_VAL(str->buf) + ZSTR_LEN(str->buf), buf, len);
     170        2321 :         ZSTR_LEN(str->buf) += len;
     171        2321 :         ZSTR_VAL(str->buf)[ZSTR_LEN(str->buf)] = '\0';
     172        2321 :         return str;
     173             : }
     174             : 
     175          63 : static string *string_append(string *str, string *append)
     176             : {
     177          63 :         if (ZSTR_LEN(append->buf) > 0) {
     178          57 :                 string_write(str, ZSTR_VAL(append->buf), ZSTR_LEN(append->buf));
     179             :         }
     180          63 :         return str;
     181             : }
     182             : 
     183        1051 : static void string_free(string *str)
     184             : {
     185        1051 :         zend_string_release(str->buf);
     186        1051 :         str->alloced = 0;
     187        1051 :         str->buf = NULL;
     188        1051 : }
     189             : /* }}} */
     190             : 
     191             : /* {{{ Object structure */
     192             : 
     193             : /* Struct for properties */
     194             : typedef struct _property_reference {
     195             :         zend_class_entry *ce;
     196             :         zend_property_info prop;
     197             : } property_reference;
     198             : 
     199             : /* Struct for parameters */
     200             : typedef struct _parameter_reference {
     201             :         uint32_t offset;
     202             :         uint32_t required;
     203             :         struct _zend_arg_info *arg_info;
     204             :         zend_function *fptr;
     205             : } parameter_reference;
     206             : 
     207             : /* Struct for type hints */
     208             : typedef struct _type_reference {
     209             :         struct _zend_arg_info *arg_info;
     210             :         zend_function *fptr;
     211             : } type_reference;
     212             : 
     213             : typedef enum {
     214             :         REF_TYPE_OTHER,      /* Must be 0 */
     215             :         REF_TYPE_FUNCTION,
     216             :         REF_TYPE_GENERATOR,
     217             :         REF_TYPE_PARAMETER,
     218             :         REF_TYPE_TYPE,
     219             :         REF_TYPE_PROPERTY,
     220             :         REF_TYPE_DYNAMIC_PROPERTY,
     221             :         REF_TYPE_CLASS_CONSTANT
     222             : } reflection_type_t;
     223             : 
     224             : /* Struct for reflection objects */
     225             : typedef struct {
     226             :         zval dummy; /* holder for the second property */
     227             :         zval obj;
     228             :         void *ptr;
     229             :         zend_class_entry *ce;
     230             :         reflection_type_t ref_type;
     231             :         unsigned int ignore_visibility:1;
     232             :         zend_object zo;
     233             : } reflection_object;
     234             : 
     235       10806 : static inline reflection_object *reflection_object_from_obj(zend_object *obj) {
     236       10806 :         return (reflection_object*)((char*)(obj) - XtOffsetOf(reflection_object, zo));
     237             : }
     238             : 
     239             : #define Z_REFLECTION_P(zv)  reflection_object_from_obj(Z_OBJ_P((zv)))
     240             : /* }}} */
     241             : 
     242             : static zend_object_handlers reflection_object_handlers;
     243             : 
     244         690 : static zval *_default_load_entry(zval *object, char *name, size_t name_len) /* {{{ */
     245             : {
     246             :         zval *value;
     247             : 
     248        1380 :         if ((value = zend_hash_str_find_ind(Z_OBJPROP_P(object), name, name_len)) == NULL) {
     249           0 :                 return NULL;
     250             :         }
     251         690 :         return value;
     252             : }
     253             : /* }}} */
     254             : 
     255         647 : static void _default_get_entry(zval *object, char *name, int name_len, zval *return_value) /* {{{ */
     256             : {
     257             :         zval *value;
     258             : 
     259         647 :         if ((value = _default_load_entry(object, name, name_len)) == NULL) {
     260           0 :                 RETURN_FALSE;
     261             :         }
     262         647 :         ZVAL_DUP(return_value, value);
     263             : }
     264             : /* }}} */
     265             : 
     266             : #ifdef ilia_0
     267             : static void _default_lookup_entry(zval *object, char *name, int name_len, zval **return_value) /* {{{ */
     268             : {
     269             :         zval **value;
     270             : 
     271             :         if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) {
     272             :                 *return_value = NULL;
     273             :         } else {
     274             :                 *return_value = *value;
     275             :         }
     276             : }
     277             : /* }}} */
     278             : #endif
     279             : 
     280         294 : static zend_function *_copy_function(zend_function *fptr) /* {{{ */
     281             : {
     282         588 :         if (fptr
     283         294 :                 && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
     284             :         {
     285             :                 zend_function *copy_fptr;
     286          18 :                 copy_fptr = emalloc(sizeof(zend_function));
     287          18 :                 memcpy(copy_fptr, fptr, sizeof(zend_function));
     288          36 :                 copy_fptr->internal_function.function_name = zend_string_copy(fptr->internal_function.function_name);
     289          18 :                 return copy_fptr;
     290             :         } else {
     291             :                 /* no copy needed */
     292         276 :                 return fptr;
     293             :         }
     294             : }
     295             : /* }}} */
     296             : 
     297        2965 : static void _free_function(zend_function *fptr) /* {{{ */
     298             : {
     299        5216 :         if (fptr
     300        2251 :                 && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
     301             :         {
     302          36 :                 zend_string_release(fptr->internal_function.function_name);
     303          36 :                 zend_free_trampoline(fptr);
     304             :         }
     305        2965 : }
     306             : /* }}} */
     307             : 
     308        3293 : static void reflection_free_objects_storage(zend_object *object) /* {{{ */
     309             : {
     310        3293 :         reflection_object *intern = reflection_object_from_obj(object);
     311             :         parameter_reference *reference;
     312             :         property_reference *prop_reference;
     313             :         type_reference *typ_reference;
     314             : 
     315        3293 :         if (intern->ptr) {
     316        3207 :                 switch (intern->ref_type) {
     317             :                 case REF_TYPE_PARAMETER:
     318         267 :                         reference = (parameter_reference*)intern->ptr;
     319         267 :                         _free_function(reference->fptr);
     320         267 :                         efree(intern->ptr);
     321         267 :                         break;
     322             :                 case REF_TYPE_TYPE:
     323          40 :                         typ_reference = (type_reference*)intern->ptr;
     324          40 :                         _free_function(typ_reference->fptr);
     325          40 :                         efree(intern->ptr);
     326          40 :                         break;
     327             :                 case REF_TYPE_FUNCTION:
     328        1943 :                         _free_function(intern->ptr);
     329        1943 :                         break;
     330             :                 case REF_TYPE_PROPERTY:
     331         233 :                         efree(intern->ptr);
     332         233 :                         break;
     333             :                 case REF_TYPE_DYNAMIC_PROPERTY:
     334           5 :                         prop_reference = (property_reference*)intern->ptr;
     335           5 :                         zend_string_release(prop_reference->prop.name);
     336           5 :                         efree(intern->ptr);
     337             :                         break;
     338             :                 case REF_TYPE_GENERATOR:
     339             :                 case REF_TYPE_CLASS_CONSTANT:
     340             :                 case REF_TYPE_OTHER:
     341             :                         break;
     342             :                 }
     343             :         }
     344        3293 :         intern->ptr = NULL;
     345        3293 :         zval_ptr_dtor(&intern->obj);
     346        3293 :         zend_object_std_dtor(object);
     347        3293 : }
     348             : /* }}} */
     349             : 
     350        3293 : static zend_object *reflection_objects_new(zend_class_entry *class_type) /* {{{ */
     351             : {
     352             :         reflection_object *intern;
     353             : 
     354        3293 :         intern = ecalloc(1, sizeof(reflection_object) + zend_object_properties_size(class_type));
     355        3293 :         intern->zo.ce = class_type;
     356             : 
     357        3293 :         zend_object_std_init(&intern->zo, class_type);
     358        3293 :         object_properties_init(&intern->zo, class_type);
     359        3293 :         intern->zo.handlers = &reflection_object_handlers;
     360        3293 :         return &intern->zo;
     361             : }
     362             : /* }}} */
     363             : 
     364        1986 : static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{ */
     365             : {
     366        1986 :         object_init_ex(object, pce);
     367        1986 :         return object;
     368             : }
     369             : /* }}} */
     370             : 
     371             : static void _const_string(string *str, char *name, zval *value, char *indent);
     372             : static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent);
     373             : static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent);
     374             : static void _class_const_string(string *str, char *name, zend_class_constant *c, char* indent);
     375             : static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent);
     376             : static void _extension_string(string *str, zend_module_entry *module, char *indent);
     377             : static void _zend_extension_string(string *str, zend_extension *extension, char *indent);
     378             : 
     379             : /* {{{ _class_string */
     380          69 : static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent)
     381             : {
     382          69 :         int count, count_static_props = 0, count_static_funcs = 0, count_shadow_props = 0;
     383             :         string sub_indent;
     384             : 
     385          69 :         string_init(&sub_indent);
     386          69 :         string_printf(&sub_indent, "%s    ", indent);
     387             : 
     388             :         /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */
     389          69 :         if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) {
     390           0 :                 string_printf(str, "%s%s", indent, ZSTR_VAL(ce->info.user.doc_comment));
     391           0 :                 string_write(str, "\n", 1);
     392             :         }
     393             : 
     394         115 :         if (obj && Z_TYPE_P(obj) == IS_OBJECT) {
     395           7 :                 string_printf(str, "%sObject of class [ ", indent);
     396             :         } else {
     397          62 :                 char *kind = "Class";
     398          62 :                 if (ce->ce_flags & ZEND_ACC_INTERFACE) {
     399           3 :                         kind = "Interface";
     400          59 :                 } else if (ce->ce_flags & ZEND_ACC_TRAIT) {
     401           2 :                         kind = "Trait";
     402             :                 }
     403          62 :                 string_printf(str, "%s%s [ ", indent, kind);
     404             :         }
     405          69 :         string_printf(str, (ce->type == ZEND_USER_CLASS) ? "<user" : "<internal");
     406          69 :         if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module) {
     407          37 :                 string_printf(str, ":%s", ce->info.internal.module->name);
     408             :         }
     409          69 :         string_printf(str, "> ");
     410          69 :         if (ce->get_iterator != NULL) {
     411           0 :                 string_printf(str, "<iterateable> ");
     412             :         }
     413          69 :         if (ce->ce_flags & ZEND_ACC_INTERFACE) {
     414           3 :                 string_printf(str, "interface ");
     415          66 :         } else if (ce->ce_flags & ZEND_ACC_TRAIT) {
     416           2 :                 string_printf(str, "trait ");
     417             :         } else {
     418          64 :                 if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
     419           3 :                         string_printf(str, "abstract ");
     420             :                 }
     421          64 :                 if (ce->ce_flags & ZEND_ACC_FINAL) {
     422           0 :                         string_printf(str, "final ");
     423             :                 }
     424          64 :                 string_printf(str, "class ");
     425             :         }
     426          69 :         string_printf(str, "%s", ZSTR_VAL(ce->name));
     427          69 :         if (ce->parent) {
     428          22 :                 string_printf(str, " extends %s", ZSTR_VAL(ce->parent->name));
     429             :         }
     430             : 
     431          69 :         if (ce->num_interfaces) {
     432             :                 uint32_t i;
     433             : 
     434          25 :                 if (ce->ce_flags & ZEND_ACC_INTERFACE) {
     435           0 :                         string_printf(str, " extends %s", ZSTR_VAL(ce->interfaces[0]->name));
     436             :                 } else {
     437          25 :                         string_printf(str, " implements %s", ZSTR_VAL(ce->interfaces[0]->name));
     438             :                 }
     439          26 :                 for (i = 1; i < ce->num_interfaces; ++i) {
     440           1 :                         string_printf(str, ", %s", ZSTR_VAL(ce->interfaces[i]->name));
     441             :                 }
     442             :         }
     443          69 :         string_printf(str, " ] {\n");
     444             : 
     445             :         /* The information where a class is declared is only available for user classes */
     446          69 :         if (ce->type == ZEND_USER_CLASS) {
     447          32 :                 string_printf(str, "%s  @@ %s %d-%d\n", indent, ZSTR_VAL(ce->info.user.filename),
     448             :                                                 ce->info.user.line_start, ce->info.user.line_end);
     449             :         }
     450             : 
     451             :         /* Constants */
     452          69 :         string_printf(str, "\n");
     453          69 :         count = zend_hash_num_elements(&ce->constants_table);
     454          69 :         string_printf(str, "%s  - Constants [%d] {\n", indent, count);
     455          69 :         if (count > 0) {
     456             :                 zend_string *key;
     457             :                 zend_class_constant *c;
     458             : 
     459         112 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
     460          48 :                         _class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent.buf));
     461             :                 } ZEND_HASH_FOREACH_END();
     462             :         }
     463          69 :         string_printf(str, "%s  }\n", indent);
     464             : 
     465             :         /* Static properties */
     466             :         /* counting static properties */
     467          69 :         count = zend_hash_num_elements(&ce->properties_info);
     468          69 :         if (count > 0) {
     469             :                 zend_property_info *prop;
     470             : 
     471         162 :                 ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) {
     472          64 :                         if(prop->flags & ZEND_ACC_SHADOW) {
     473          11 :                                 count_shadow_props++;
     474          53 :                         } else if (prop->flags & ZEND_ACC_STATIC) {
     475           3 :                                 count_static_props++;
     476             :                         }
     477             :                 } ZEND_HASH_FOREACH_END();
     478             :         }
     479             : 
     480             :         /* static properties */
     481          69 :         string_printf(str, "\n%s  - Static properties [%d] {\n", indent, count_static_props);
     482          69 :         if (count_static_props > 0) {
     483             :                 zend_property_info *prop;
     484             : 
     485          12 :                 ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) {
     486           5 :                         if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) {
     487           3 :                                 _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.buf));
     488             :                         }
     489             :                 } ZEND_HASH_FOREACH_END();
     490             :         }
     491          69 :         string_printf(str, "%s  }\n", indent);
     492             : 
     493             :         /* Static methods */
     494             :         /* counting static methods */
     495          69 :         count = zend_hash_num_elements(&ce->function_table);
     496          69 :         if (count > 0) {
     497             :                 zend_function *mptr;
     498             : 
     499        1562 :                 ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) {
     500         783 :                         if (mptr->common.fn_flags & ZEND_ACC_STATIC
     501         783 :                                 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
     502             :                         {
     503          27 :                                 count_static_funcs++;
     504             :                         }
     505             :                 } ZEND_HASH_FOREACH_END();
     506             :         }
     507             : 
     508             :         /* static methods */
     509          69 :         string_printf(str, "\n%s  - Static methods [%d] {", indent, count_static_funcs);
     510          69 :         if (count_static_funcs > 0) {
     511             :                 zend_function *mptr;
     512             : 
     513        1287 :                 ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) {
     514         658 :                         if (mptr->common.fn_flags & ZEND_ACC_STATIC
     515         658 :                                 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
     516             :                         {
     517          27 :                                 string_printf(str, "\n");
     518          27 :                                 _function_string(str, mptr, ce, ZSTR_VAL(sub_indent.buf));
     519             :                         }
     520             :                 } ZEND_HASH_FOREACH_END();
     521             :         } else {
     522          44 :                 string_printf(str, "\n");
     523             :         }
     524          69 :         string_printf(str, "%s  }\n", indent);
     525             : 
     526             :         /* Default/Implicit properties */
     527          69 :         count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props;
     528          69 :         string_printf(str, "\n%s  - Properties [%d] {\n", indent, count);
     529          69 :         if (count > 0) {
     530             :                 zend_property_info *prop;
     531             : 
     532         144 :                 ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) {
     533          57 :                         if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) {
     534          50 :                                 _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.buf));
     535             :                         }
     536             :                 } ZEND_HASH_FOREACH_END();
     537             :         }
     538          69 :         string_printf(str, "%s  }\n", indent);
     539             : 
     540         108 :         if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) {
     541             :                 string       dyn;
     542           7 :                 HashTable    *properties = Z_OBJ_HT_P(obj)->get_properties(obj);
     543             :                 zend_string  *prop_name;
     544             : 
     545           7 :                 string_init(&dyn);
     546           7 :                 count = 0;
     547             : 
     548           7 :                 if (properties && zend_hash_num_elements(properties)) {
     549          34 :                         ZEND_HASH_FOREACH_STR_KEY(properties, prop_name) {
     550          14 :                                 if (prop_name && ZSTR_LEN(prop_name) && ZSTR_VAL(prop_name)[0]) { /* skip all private and protected properties */
     551          11 :                                         if (!zend_hash_exists(&ce->properties_info, prop_name)) {
     552           5 :                                                 count++;
     553           5 :                                                 _property_string(&dyn, NULL, ZSTR_VAL(prop_name), ZSTR_VAL(sub_indent.buf));
     554             :                                         }
     555             :                                 }
     556             :                         } ZEND_HASH_FOREACH_END();
     557             :                 }
     558             : 
     559           7 :                 string_printf(str, "\n%s  - Dynamic properties [%d] {\n", indent, count);
     560           7 :                 string_append(str, &dyn);
     561           7 :                 string_printf(str, "%s  }\n", indent);
     562           7 :                 string_free(&dyn);
     563             :         }
     564             : 
     565             :         /* Non static methods */
     566          69 :         count = zend_hash_num_elements(&ce->function_table) - count_static_funcs;
     567          69 :         if (count > 0) {
     568             :                 zend_function *mptr;
     569             :                 zend_string *key;
     570             :                 string dyn;
     571             : 
     572          52 :                 count = 0;
     573          52 :                 string_init(&dyn);
     574             : 
     575        1552 :                 ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, mptr) {
     576        1510 :                         if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0
     577         760 :                                 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
     578             :                         {
     579         714 :                                 size_t len = ZSTR_LEN(mptr->common.function_name);
     580             : 
     581             :                                 /* Do not display old-style inherited constructors */
     582         742 :                                 if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0
     583             :                                         || mptr->common.scope == ce
     584          25 :                                         || !key
     585           3 :                                         || zend_binary_strcasecmp(ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(mptr->common.function_name), len) == 0)
     586             :                                 {
     587             :                                         zend_function *closure;
     588             :                                         /* see if this is a closure */
     589         714 :                                         if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
     590           0 :                                                 && memcmp(ZSTR_VAL(mptr->common.function_name), ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
     591           0 :                                                 && (closure = zend_get_closure_invoke_method(Z_OBJ_P(obj))) != NULL)
     592             :                                         {
     593           0 :                                                 mptr = closure;
     594             :                                         } else {
     595         714 :                                                 closure = NULL;
     596             :                                         }
     597         714 :                                         string_printf(&dyn, "\n");
     598         714 :                                         _function_string(&dyn, mptr, ce, ZSTR_VAL(sub_indent.buf));
     599         714 :                                         count++;
     600         714 :                                         _free_function(closure);
     601             :                                 }
     602             :                         }
     603             :                 } ZEND_HASH_FOREACH_END();
     604          52 :                 string_printf(str, "\n%s  - Methods [%d] {", indent, count);
     605          52 :                 if (!count) {
     606           2 :                         string_printf(str, "\n");
     607             :                 }
     608          52 :                 string_append(str, &dyn);
     609          52 :                 string_free(&dyn);
     610             :         } else {
     611          17 :                 string_printf(str, "\n%s  - Methods [0] {\n", indent);
     612             :         }
     613          69 :         string_printf(str, "%s  }\n", indent);
     614             : 
     615          69 :         string_printf(str, "%s}\n", indent);
     616          69 :         string_free(&sub_indent);
     617          69 : }
     618             : /* }}} */
     619             : 
     620             : /* {{{ _const_string */
     621          15 : static void _const_string(string *str, char *name, zval *value, char *indent)
     622             : {
     623          15 :         char *type = zend_zval_type_name(value);
     624             : 
     625          15 :         if (Z_TYPE_P(value) == IS_ARRAY) {
     626           0 :                 string_printf(str, "%s    Constant [ %s %s ] { Array }\n",
     627             :                                                 indent, type, name);
     628             :         } else {
     629          15 :                 zend_string *value_str = zval_get_string(value);
     630          15 :                 string_printf(str, "%s    Constant [ %s %s ] { %s }\n",
     631             :                                                 indent, type, name, ZSTR_VAL(value_str));
     632             :                 zend_string_release(value_str);
     633             :         }
     634          15 : }
     635             : /* }}} */
     636             : 
     637             : /* {{{ _class_const_string */
     638          61 : static void _class_const_string(string *str, char *name, zend_class_constant *c, char *indent)
     639             : {
     640          61 :         char *visibility = zend_visibility_string(Z_ACCESS_FLAGS(c->value));
     641             :         char *type;
     642             : 
     643          61 :         zval_update_constant_ex(&c->value, c->ce);
     644          61 :         type = zend_zval_type_name(&c->value);
     645             : 
     646         122 :         if (Z_TYPE(c->value) == IS_ARRAY) {
     647           1 :                 string_printf(str, "%sConstant [ %s %s %s ] { Array }\n",
     648             :                                                 indent, visibility, type, name);
     649             :         } else {
     650         120 :                 zend_string *value_str = zval_get_string(&c->value);
     651             : 
     652          60 :                 string_printf(str, "%sConstant [ %s %s %s ] { %s }\n",
     653             :                                                 indent, visibility, type, name, ZSTR_VAL(value_str));
     654             : 
     655             :                 zend_string_release(value_str);
     656             :         }
     657          61 : }
     658             : /* }}} */
     659             : 
     660             : /* {{{ _get_recv_opcode */
     661         117 : static zend_op* _get_recv_op(zend_op_array *op_array, uint32_t offset)
     662             : {
     663         117 :         zend_op *op = op_array->opcodes;
     664         117 :         zend_op *end = op + op_array->last;
     665             : 
     666         117 :         ++offset;
     667         402 :         while (op < end) {
     668         754 :                 if ((op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT
     669         469 :                     || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == offset)
     670             :                 {
     671         117 :                         return op;
     672             :                 }
     673         168 :                 ++op;
     674             :         }
     675           0 :         return NULL;
     676             : }
     677             : /* }}} */
     678             : 
     679             : /* {{{ _parameter_string */
     680         603 : static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg_info *arg_info, uint32_t offset, uint32_t required, char* indent)
     681             : {
     682         603 :         string_printf(str, "Parameter #%d [ ", offset);
     683         603 :         if (offset >= required) {
     684         187 :                 string_printf(str, "<optional> ");
     685             :         } else {
     686         416 :                 string_printf(str, "<required> ");
     687             :         }
     688         603 :         if (arg_info->class_name) {
     689          18 :                 string_printf(str, "%s ",
     690           7 :                         (fptr->type == ZEND_INTERNAL_FUNCTION &&
     691           4 :                          !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ?
     692           2 :                         ((zend_internal_arg_info*)arg_info)->class_name :
     693           5 :                         ZSTR_VAL(arg_info->class_name));
     694           7 :                 if (arg_info->allow_null) {
     695           1 :                         string_printf(str, "or NULL ");
     696             :                 }
     697         596 :         } else if (arg_info->type_hint) {
     698          12 :                 string_printf(str, "%s ", zend_get_type_by_const(arg_info->type_hint));
     699          12 :                 if (arg_info->allow_null) {
     700           1 :                         string_printf(str, "or NULL ");
     701             :                 }
     702             :         }
     703         603 :         if (arg_info->pass_by_reference) {
     704          14 :                 string_write(str, "&", sizeof("&")-1);
     705             :         }
     706         603 :         if (arg_info->is_variadic) {
     707           1 :                 string_write(str, "...", sizeof("...")-1);
     708             :         }
     709         603 :         if (arg_info->name) {
     710        1768 :                 string_printf(str, "$%s",
     711         603 :                         (fptr->type == ZEND_INTERNAL_FUNCTION &&
     712         562 :                          !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ?
     713         560 :                         ((zend_internal_arg_info*)arg_info)->name :
     714          43 :                         ZSTR_VAL(arg_info->name));
     715             :         } else {
     716           0 :                 string_printf(str, "$param%d", offset);
     717             :         }
     718         603 :         if (fptr->type == ZEND_USER_FUNCTION && offset >= required) {
     719          28 :                 zend_op *precv = _get_recv_op((zend_op_array*)fptr, offset);
     720          28 :                 if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) {
     721             :                         zval zv;
     722             : 
     723          27 :                         string_write(str, " = ", sizeof(" = ")-1);
     724          27 :                         ZVAL_DUP(&zv, RT_CONSTANT(&fptr->op_array, precv->op2));
     725          27 :                         zval_update_constant_ex(&zv, fptr->common.scope);
     726          27 :                         if (Z_TYPE(zv) == IS_TRUE) {
     727           0 :                                 string_write(str, "true", sizeof("true")-1);
     728          27 :                         } else if (Z_TYPE(zv) == IS_FALSE) {
     729           2 :                                 string_write(str, "false", sizeof("false")-1);
     730          25 :                         } else if (Z_TYPE(zv) == IS_NULL) {
     731           8 :                                 string_write(str, "NULL", sizeof("NULL")-1);
     732          17 :                         } else if (Z_TYPE(zv) == IS_STRING) {
     733          12 :                                 string_write(str, "'", sizeof("'")-1);
     734          12 :                                 string_write(str, Z_STRVAL(zv), MIN(Z_STRLEN(zv), 15));
     735          12 :                                 if (Z_STRLEN(zv) > 15) {
     736           1 :                                         string_write(str, "...", sizeof("...")-1);
     737             :                                 }
     738          12 :                                 string_write(str, "'", sizeof("'")-1);
     739           5 :                         } else if (Z_TYPE(zv) == IS_ARRAY) {
     740           1 :                                 string_write(str, "Array", sizeof("Array")-1);
     741             :                         } else {
     742           4 :                                 zend_string *zv_str = zval_get_string(&zv);
     743           4 :                                 string_write(str, ZSTR_VAL(zv_str), ZSTR_LEN(zv_str));
     744             :                                 zend_string_release(zv_str);
     745             :                         }
     746          27 :                         zval_ptr_dtor(&zv);
     747             :                 }
     748             :         }
     749         603 :         string_write(str, " ]", sizeof(" ]")-1);
     750         603 : }
     751             : /* }}} */
     752             : 
     753             : /* {{{ _function_parameter_string */
     754         911 : static void _function_parameter_string(string *str, zend_function *fptr, char* indent)
     755             : {
     756         911 :         struct _zend_arg_info *arg_info = fptr->common.arg_info;
     757         911 :         uint32_t i, num_args, required = fptr->common.required_num_args;
     758             : 
     759         911 :         if (!arg_info) {
     760          65 :                 return;
     761             :         }
     762             : 
     763         846 :         num_args = fptr->common.num_args;
     764         846 :         if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) {
     765           0 :                 num_args++;
     766             :         }
     767         846 :         string_printf(str, "\n");
     768         846 :         string_printf(str, "%s- Parameters [%d] {\n", indent, num_args);
     769        1442 :         for (i = 0; i < num_args; i++) {
     770         596 :                 string_printf(str, "%s  ", indent);
     771         596 :                 _parameter_string(str, fptr, arg_info, i, required, indent);
     772         596 :                 string_write(str, "\n", sizeof("\n")-1);
     773         596 :                 arg_info++;
     774             :         }
     775         846 :         string_printf(str, "%s}\n", indent);
     776             : }
     777             : /* }}} */
     778             : 
     779             : /* {{{ _function_closure_string */
     780           0 : static void _function_closure_string(string *str, zend_function *fptr, char* indent)
     781             : {
     782             :         uint32_t i, count;
     783             :         zend_string *key;
     784             :         HashTable *static_variables;
     785             : 
     786           0 :         if (fptr->type != ZEND_USER_FUNCTION || !fptr->op_array.static_variables) {
     787           0 :                 return;
     788             :         }
     789             : 
     790           0 :         static_variables = fptr->op_array.static_variables;
     791           0 :         count = zend_hash_num_elements(static_variables);
     792             : 
     793           0 :         if (!count) {
     794           0 :                 return;
     795             :         }
     796             : 
     797           0 :         string_printf(str, "\n");
     798           0 :         string_printf(str, "%s- Bound Variables [%d] {\n", indent, zend_hash_num_elements(static_variables));
     799           0 :         i = 0;
     800           0 :         ZEND_HASH_FOREACH_STR_KEY(static_variables, key) {
     801           0 :                 string_printf(str, "%s    Variable #%d [ $%s ]\n", indent, i++, ZSTR_VAL(key));
     802             :         } ZEND_HASH_FOREACH_END();
     803           0 :         string_printf(str, "%s}\n", indent);
     804             : }
     805             : /* }}} */
     806             : 
     807             : /* {{{ _function_string */
     808         911 : static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent)
     809             : {
     810             :         string param_indent;
     811             :         zend_function *overwrites;
     812             :         zend_string *lc_name;
     813             :         size_t lc_name_len;
     814             : 
     815             :         /* TBD: Repair indenting of doc comment (or is this to be done in the parser?)
     816             :          * What's "wrong" is that any whitespace before the doc comment start is
     817             :          * swallowed, leading to an unaligned comment.
     818             :          */
     819         911 :         if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
     820           2 :                 string_printf(str, "%s%s\n", indent, ZSTR_VAL(fptr->op_array.doc_comment));
     821             :         }
     822             : 
     823         911 :         string_write(str, indent, strlen(indent));
     824         911 :         string_printf(str, fptr->common.fn_flags & ZEND_ACC_CLOSURE ? "Closure [ " : (fptr->common.scope ? "Method [ " : "Function [ "));
     825         911 :         string_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal");
     826         911 :         if (fptr->common.fn_flags & ZEND_ACC_DEPRECATED) {
     827           0 :                 string_printf(str, ", deprecated");
     828             :         }
     829         911 :         if (fptr->type == ZEND_INTERNAL_FUNCTION && ((zend_internal_function*)fptr)->module) {
     830         856 :                 string_printf(str, ":%s", ((zend_internal_function*)fptr)->module->name);
     831             :         }
     832             : 
     833         911 :         if (scope && fptr->common.scope) {
     834         773 :                 if (fptr->common.scope != scope) {
     835         234 :                         string_printf(str, ", inherits %s", ZSTR_VAL(fptr->common.scope->name));
     836         539 :                 } else if (fptr->common.scope->parent) {
     837          65 :                         lc_name_len = ZSTR_LEN(fptr->common.function_name);
     838          65 :                         lc_name = zend_string_alloc(lc_name_len, 0);
     839          65 :                         zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(fptr->common.function_name), lc_name_len);
     840         130 :                         if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) {
     841          17 :                                 if (fptr->common.scope != overwrites->common.scope) {
     842          17 :                                         string_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name));
     843             :                                 }
     844             :                         }
     845          65 :                         efree(lc_name);
     846             :                 }
     847             :         }
     848         911 :         if (fptr->common.prototype && fptr->common.prototype->common.scope) {
     849          69 :                 string_printf(str, ", prototype %s", ZSTR_VAL(fptr->common.prototype->common.scope->name));
     850             :         }
     851         911 :         if (fptr->common.fn_flags & ZEND_ACC_CTOR) {
     852          28 :                 string_printf(str, ", ctor");
     853             :         }
     854         911 :         if (fptr->common.fn_flags & ZEND_ACC_DTOR) {
     855           2 :                 string_printf(str, ", dtor");
     856             :         }
     857         911 :         string_printf(str, "> ");
     858             : 
     859         911 :         if (fptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
     860          11 :                 string_printf(str, "abstract ");
     861             :         }
     862         911 :         if (fptr->common.fn_flags & ZEND_ACC_FINAL) {
     863          39 :                 string_printf(str, "final ");
     864             :         }
     865         911 :         if (fptr->common.fn_flags & ZEND_ACC_STATIC) {
     866          29 :                 string_printf(str, "static ");
     867             :         }
     868             : 
     869         911 :         if (fptr->common.scope) {
     870             :                 /* These are mutually exclusive */
     871         773 :                 switch (fptr->common.fn_flags & ZEND_ACC_PPP_MASK) {
     872             :                         case ZEND_ACC_PUBLIC:
     873         740 :                                 string_printf(str, "public ");
     874         740 :                                 break;
     875             :                         case ZEND_ACC_PRIVATE:
     876          28 :                                 string_printf(str, "private ");
     877          28 :                                 break;
     878             :                         case ZEND_ACC_PROTECTED:
     879           5 :                                 string_printf(str, "protected ");
     880           5 :                                 break;
     881             :                         default:
     882           0 :                                 string_printf(str, "<visibility error> ");
     883             :                                 break;
     884             :                 }
     885         773 :                 string_printf(str, "method ");
     886             :         } else {
     887         138 :                 string_printf(str, "function ");
     888             :         }
     889             : 
     890         911 :         if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
     891           0 :                 string_printf(str, "&");
     892             :         }
     893         911 :         string_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name));
     894             :         /* The information where a function is declared is only available for user classes */
     895         911 :         if (fptr->type == ZEND_USER_FUNCTION) {
     896         108 :                 string_printf(str, "%s  @@ %s %d - %d\n", indent,
     897          54 :                                                 ZSTR_VAL(fptr->op_array.filename),
     898             :                                                 fptr->op_array.line_start,
     899             :                                                 fptr->op_array.line_end);
     900             :         }
     901         911 :         string_init(&param_indent);
     902         911 :         string_printf(&param_indent, "%s  ", indent);
     903         911 :         if (fptr->common.fn_flags & ZEND_ACC_CLOSURE) {
     904           0 :                 _function_closure_string(str, fptr, ZSTR_VAL(param_indent.buf));
     905             :         }
     906         911 :         _function_parameter_string(str, fptr, ZSTR_VAL(param_indent.buf));
     907         911 :         string_free(&param_indent);
     908         911 :         if (fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
     909           2 :                 string_printf(str, "  %s- Return [ ", indent);
     910           2 :                 if (fptr->common.arg_info[-1].class_name) {
     911           3 :                         string_printf(str, "%s ",
     912           1 :                                 (fptr->type == ZEND_INTERNAL_FUNCTION &&
     913           1 :                                  !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ?
     914           0 :                                         ((zend_internal_arg_info*)(fptr->common.arg_info - 1))->class_name :
     915           1 :                                         ZSTR_VAL(fptr->common.arg_info[-1].class_name));
     916           1 :                         if (fptr->common.arg_info[-1].allow_null) {
     917           0 :                                 string_printf(str, "or NULL ");
     918             :                         }
     919           1 :                 } else if (fptr->common.arg_info[-1].type_hint) {
     920           1 :                         string_printf(str, "%s ", zend_get_type_by_const(fptr->common.arg_info[-1].type_hint));
     921           1 :                         if (fptr->common.arg_info[-1].allow_null) {
     922           0 :                                 string_printf(str, "or NULL ");
     923             :                         }
     924             :                 }
     925           2 :                 string_printf(str, "]\n");
     926             :         }
     927         911 :         string_printf(str, "%s}\n", indent);
     928         911 : }
     929             : /* }}} */
     930             : 
     931             : /* {{{ _property_string */
     932          71 : static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent)
     933             : {
     934             :         const char *class_name;
     935             : 
     936          71 :         string_printf(str, "%sProperty [ ", indent);
     937          71 :         if (!prop) {
     938           5 :                 string_printf(str, "<dynamic> public $%s", prop_name);
     939             :         } else {
     940          66 :                 if (!(prop->flags & ZEND_ACC_STATIC)) {
     941          60 :                         if (prop->flags & ZEND_ACC_IMPLICIT_PUBLIC) {
     942           0 :                                 string_write(str, "<implicit> ", sizeof("<implicit> ") - 1);
     943             :                         } else {
     944          60 :                                 string_write(str, "<default> ", sizeof("<default> ") - 1);
     945             :                         }
     946             :                 }
     947             : 
     948             :                 /* These are mutually exclusive */
     949          66 :                 switch (prop->flags & ZEND_ACC_PPP_MASK) {
     950             :                         case ZEND_ACC_PUBLIC:
     951          40 :                                 string_printf(str, "public ");
     952          40 :                                 break;
     953             :                         case ZEND_ACC_PRIVATE:
     954           9 :                                 string_printf(str, "private ");
     955           9 :                                 break;
     956             :                         case ZEND_ACC_PROTECTED:
     957          17 :                                 string_printf(str, "protected ");
     958             :                                 break;
     959             :                 }
     960          66 :                 if(prop->flags & ZEND_ACC_STATIC) {
     961           6 :                         string_printf(str, "static ");
     962             :                 }
     963             : 
     964          66 :                 zend_unmangle_property_name(prop->name, &class_name, (const char**)&prop_name);
     965          66 :                 string_printf(str, "$%s", prop_name);
     966             :         }
     967             : 
     968          71 :         string_printf(str, " ]\n");
     969          71 : }
     970             : /* }}} */
     971             : 
     972         766 : static int _extension_ini_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
     973             : {
     974         766 :         zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el);
     975         766 :         string *str = va_arg(args, string *);
     976         766 :         char *indent = va_arg(args, char *);
     977         766 :         int number = va_arg(args, int);
     978         766 :         char *comma = "";
     979             : 
     980         766 :         if (number == ini_entry->module_number) {
     981           3 :                 string_printf(str, "    %sEntry [ %s <", indent, ZSTR_VAL(ini_entry->name));
     982           3 :                 if (ini_entry->modifiable == ZEND_INI_ALL) {
     983           3 :                         string_printf(str, "ALL");
     984             :                 } else {
     985           0 :                         if (ini_entry->modifiable & ZEND_INI_USER) {
     986           0 :                                 string_printf(str, "USER");
     987           0 :                                 comma = ",";
     988             :                         }
     989           0 :                         if (ini_entry->modifiable & ZEND_INI_PERDIR) {
     990           0 :                                 string_printf(str, "%sPERDIR", comma);
     991           0 :                                 comma = ",";
     992             :                         }
     993           0 :                         if (ini_entry->modifiable & ZEND_INI_SYSTEM) {
     994           0 :                                 string_printf(str, "%sSYSTEM", comma);
     995             :                         }
     996             :                 }
     997             : 
     998           3 :                 string_printf(str, "> ]\n");
     999           3 :                 string_printf(str, "    %s  Current = '%s'\n", indent, ini_entry->value ? ZSTR_VAL(ini_entry->value) : "");
    1000           3 :                 if (ini_entry->modified) {
    1001           0 :                         string_printf(str, "    %s  Default = '%s'\n", indent, ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : "");
    1002             :                 }
    1003           3 :                 string_printf(str, "    %s}\n", indent);
    1004             :         }
    1005         766 :         return ZEND_HASH_APPLY_KEEP;
    1006             : }
    1007             : /* }}} */
    1008             : 
    1009         579 : static int _extension_class_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
    1010             : {
    1011         579 :         zend_class_entry *ce = (zend_class_entry*)Z_PTR_P(el);
    1012         579 :         string *str = va_arg(args, string *);
    1013         579 :         char *indent = va_arg(args, char *);
    1014         579 :         struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*);
    1015         579 :         int *num_classes = va_arg(args, int*);
    1016             : 
    1017         579 :         if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) {
    1018             :                 /* dump class if it is not an alias */
    1019          30 :                 if (!zend_binary_strcasecmp(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key))) {
    1020          30 :                         string_printf(str, "\n");
    1021          30 :                         _class_string(str, ce, NULL, indent);
    1022          30 :                         (*num_classes)++;
    1023             :                 }
    1024             :         }
    1025         579 :         return ZEND_HASH_APPLY_KEEP;
    1026             : }
    1027             : /* }}} */
    1028             : 
    1029        7746 : static int _extension_const_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
    1030             : {
    1031        7746 :         zend_constant *constant = (zend_constant*)Z_PTR_P(el);
    1032        7746 :         string *str = va_arg(args, string *);
    1033        7746 :         char *indent = va_arg(args, char *);
    1034        7746 :         struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*);
    1035        7746 :         int *num_classes = va_arg(args, int*);
    1036             : 
    1037        7746 :         if (constant->module_number  == module->module_number) {
    1038          15 :                 _const_string(str, ZSTR_VAL(constant->name), &constant->value, indent);
    1039          15 :                 (*num_classes)++;
    1040             :         }
    1041        7746 :         return ZEND_HASH_APPLY_KEEP;
    1042             : }
    1043             : /* }}} */
    1044             : 
    1045           3 : static void _extension_string(string *str, zend_module_entry *module, char *indent) /* {{{ */
    1046             : {
    1047           3 :         string_printf(str, "%sExtension [ ", indent);
    1048           3 :         if (module->type == MODULE_PERSISTENT) {
    1049           3 :                 string_printf(str, "<persistent>");
    1050             :         }
    1051           3 :         if (module->type == MODULE_TEMPORARY) {
    1052           0 :                 string_printf(str, "<temporary>" );
    1053             :         }
    1054           3 :         string_printf(str, " extension #%d %s version %s ] {\n",
    1055             :                                         module->module_number, module->name,
    1056             :                                         (module->version == NO_VERSION_YET) ? "<no_version>" : module->version);
    1057             : 
    1058           3 :         if (module->deps) {
    1059           0 :                 const zend_module_dep* dep = module->deps;
    1060             : 
    1061           0 :                 string_printf(str, "\n  - Dependencies {\n");
    1062             : 
    1063           0 :                 while(dep->name) {
    1064           0 :                         string_printf(str, "%s    Dependency [ %s (", indent, dep->name);
    1065             : 
    1066           0 :                         switch(dep->type) {
    1067             :                         case MODULE_DEP_REQUIRED:
    1068           0 :                                 string_write(str, "Required", sizeof("Required") - 1);
    1069           0 :                                 break;
    1070             :                         case MODULE_DEP_CONFLICTS:
    1071           0 :                                 string_write(str, "Conflicts", sizeof("Conflicts") - 1);
    1072           0 :                                 break;
    1073             :                         case MODULE_DEP_OPTIONAL:
    1074           0 :                                 string_write(str, "Optional", sizeof("Optional") - 1);
    1075           0 :                                 break;
    1076             :                         default:
    1077           0 :                                 string_write(str, "Error", sizeof("Error") - 1); /* shouldn't happen */
    1078             :                                 break;
    1079             :                         }
    1080             : 
    1081           0 :                         if (dep->rel) {
    1082           0 :                                 string_printf(str, " %s", dep->rel);
    1083             :                         }
    1084           0 :                         if (dep->version) {
    1085           0 :                                 string_printf(str, " %s", dep->version);
    1086             :                         }
    1087           0 :                         string_write(str, ") ]\n", sizeof(") ]\n") - 1);
    1088           0 :                         dep++;
    1089             :                 }
    1090           0 :                 string_printf(str, "%s  }\n", indent);
    1091             :         }
    1092             : 
    1093             :         {
    1094             :                 string str_ini;
    1095           3 :                 string_init(&str_ini);
    1096           3 :                 zend_hash_apply_with_arguments(EG(ini_directives), (apply_func_args_t) _extension_ini_string, 3, &str_ini, indent, module->module_number);
    1097           3 :                 if (ZSTR_LEN(str_ini.buf) > 0) {
    1098           1 :                         string_printf(str, "\n  - INI {\n");
    1099           1 :                         string_append(str, &str_ini);
    1100           1 :                         string_printf(str, "%s  }\n", indent);
    1101             :                 }
    1102           3 :                 string_free(&str_ini);
    1103             :         }
    1104             : 
    1105             :         {
    1106             :                 string str_constants;
    1107           3 :                 int num_constants = 0;
    1108             : 
    1109           3 :                 string_init(&str_constants);
    1110           3 :                 zend_hash_apply_with_arguments(EG(zend_constants), (apply_func_args_t) _extension_const_string, 4, &str_constants, indent, module, &num_constants);
    1111           3 :                 if (num_constants) {
    1112           1 :                         string_printf(str, "\n  - Constants [%d] {\n", num_constants);
    1113           1 :                         string_append(str, &str_constants);
    1114           1 :                         string_printf(str, "%s  }\n", indent);
    1115             :                 }
    1116           3 :                 string_free(&str_constants);
    1117             :         }
    1118             : 
    1119             :         {
    1120             :                 zend_function *fptr;
    1121           3 :                 int first = 1;
    1122             : 
    1123       13221 :                 ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) {
    1124       13218 :                         if (fptr->common.type==ZEND_INTERNAL_FUNCTION
    1125       13218 :                                 && fptr->internal_function.module == module) {
    1126          10 :                                 if (first) {
    1127           1 :                                         string_printf(str, "\n  - Functions {\n");
    1128           1 :                                         first = 0;
    1129             :                                 }
    1130          10 :                                 _function_string(str, fptr, NULL, "    ");
    1131             :                         }
    1132             :                 } ZEND_HASH_FOREACH_END();
    1133           3 :                 if (!first) {
    1134           1 :                         string_printf(str, "%s  }\n", indent);
    1135             :                 }
    1136             :         }
    1137             : 
    1138             :         {
    1139             :                 string str_classes;
    1140             :                 string sub_indent;
    1141           3 :                 int num_classes = 0;
    1142             : 
    1143           3 :                 string_init(&sub_indent);
    1144           3 :                 string_printf(&sub_indent, "%s    ", indent);
    1145           3 :                 string_init(&str_classes);
    1146           3 :                 zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) _extension_class_string, 4, &str_classes, ZSTR_VAL(sub_indent.buf), module, &num_classes);
    1147           3 :                 if (num_classes) {
    1148           2 :                         string_printf(str, "\n  - Classes [%d] {", num_classes);
    1149           2 :                         string_append(str, &str_classes);
    1150           2 :                         string_printf(str, "%s  }\n", indent);
    1151             :                 }
    1152           3 :                 string_free(&str_classes);
    1153           3 :                 string_free(&sub_indent);
    1154             :         }
    1155             : 
    1156           3 :         string_printf(str, "%s}\n", indent);
    1157           3 : }
    1158             : /* }}} */
    1159             : 
    1160           0 : static void _zend_extension_string(string *str, zend_extension *extension, char *indent) /* {{{ */
    1161             : {
    1162           0 :         string_printf(str, "%sZend Extension [ %s ", indent, extension->name);
    1163             : 
    1164           0 :         if (extension->version) {
    1165           0 :                 string_printf(str, "%s ", extension->version);
    1166             :         }
    1167           0 :         if (extension->copyright) {
    1168           0 :                 string_printf(str, "%s ", extension->copyright);
    1169             :         }
    1170           0 :         if (extension->author) {
    1171           0 :                 string_printf(str, "by %s ", extension->author);
    1172             :         }
    1173           0 :         if (extension->URL) {
    1174           0 :                 string_printf(str, "<%s> ", extension->URL);
    1175             :         }
    1176             : 
    1177           0 :         string_printf(str, "]\n");
    1178           0 : }
    1179             : /* }}} */
    1180             : 
    1181             : /* {{{ _function_check_flag */
    1182         437 : static void _function_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask)
    1183             : {
    1184             :         reflection_object *intern;
    1185             :         zend_function *mptr;
    1186             : 
    1187         437 :         if (zend_parse_parameters_none() == FAILURE) {
    1188           6 :                 return;
    1189             :         }
    1190         862 :         GET_REFLECTION_OBJECT_PTR(mptr);
    1191         431 :         RETURN_BOOL(mptr->common.fn_flags & mask);
    1192             : }
    1193             : /* }}} */
    1194             : 
    1195             : /* {{{ zend_reflection_class_factory */
    1196         145 : PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object)
    1197             : {
    1198             :         reflection_object *intern;
    1199             :         zval name;
    1200             : 
    1201         145 :         ZVAL_STR_COPY(&name, ce->name);
    1202         145 :         reflection_instantiate(reflection_class_ptr, object);
    1203         145 :         intern = Z_REFLECTION_P(object);
    1204         145 :         intern->ptr = ce;
    1205         145 :         intern->ref_type = REF_TYPE_OTHER;
    1206         145 :         intern->ce = ce;
    1207         435 :         reflection_update_property(object, "name", &name);
    1208         145 : }
    1209             : /* }}} */
    1210             : 
    1211             : /* {{{ reflection_extension_factory */
    1212           2 : static void reflection_extension_factory(zval *object, const char *name_str)
    1213             : {
    1214             :         reflection_object *intern;
    1215             :         zval name;
    1216           2 :         size_t name_len = strlen(name_str);
    1217             :         zend_string *lcname;
    1218             :         struct _zend_module_entry *module;
    1219             : 
    1220           2 :         lcname = zend_string_alloc(name_len, 0);
    1221           2 :         zend_str_tolower_copy(ZSTR_VAL(lcname), name_str, name_len);
    1222           2 :         module = zend_hash_find_ptr(&module_registry, lcname);
    1223             :         zend_string_free(lcname);
    1224           2 :         if (!module) {
    1225           0 :                 return;
    1226             :         }
    1227             : 
    1228           2 :         reflection_instantiate(reflection_extension_ptr, object);
    1229           2 :         intern = Z_REFLECTION_P(object);
    1230           4 :         ZVAL_STRINGL(&name, module->name, name_len);
    1231           2 :         intern->ptr = module;
    1232           2 :         intern->ref_type = REF_TYPE_OTHER;
    1233           2 :         intern->ce = NULL;
    1234           6 :         reflection_update_property(object, "name", &name);
    1235             : }
    1236             : /* }}} */
    1237             : 
    1238             : /* {{{ reflection_parameter_factory */
    1239         246 : static void reflection_parameter_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, uint32_t offset, uint32_t required, zval *object)
    1240             : {
    1241             :         reflection_object *intern;
    1242             :         parameter_reference *reference;
    1243             :         zval name;
    1244             : 
    1245         246 :         if (arg_info->name) {
    1246         467 :                 if (fptr->type == ZEND_INTERNAL_FUNCTION &&
    1247         114 :                     !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
    1248         214 :                         ZVAL_STRING(&name, ((zend_internal_arg_info*)arg_info)->name);
    1249             :                 } else {
    1250         139 :                         ZVAL_STR_COPY(&name, arg_info->name);
    1251             :                 }
    1252             :         } else {
    1253           0 :                 ZVAL_NULL(&name);
    1254             :         }
    1255         246 :         reflection_instantiate(reflection_parameter_ptr, object);
    1256         246 :         intern = Z_REFLECTION_P(object);
    1257         246 :         reference = (parameter_reference*) emalloc(sizeof(parameter_reference));
    1258         246 :         reference->arg_info = arg_info;
    1259         246 :         reference->offset = offset;
    1260         246 :         reference->required = required;
    1261         246 :         reference->fptr = fptr;
    1262         246 :         intern->ptr = reference;
    1263         246 :         intern->ref_type = REF_TYPE_PARAMETER;
    1264         246 :         intern->ce = fptr->common.scope;
    1265         246 :         if (closure_object) {
    1266             :                 Z_ADDREF_P(closure_object);
    1267          16 :                 ZVAL_COPY_VALUE(&intern->obj, closure_object);
    1268             :         }
    1269         738 :         reflection_update_property(object, "name", &name);
    1270         246 : }
    1271             : /* }}} */
    1272             : 
    1273             : /* {{{ reflection_type_factory */
    1274          40 : static void reflection_type_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, zval *object)
    1275             : {
    1276             :         reflection_object *intern;
    1277             :         type_reference *reference;
    1278             : 
    1279          40 :         reflection_instantiate(reflection_type_ptr, object);
    1280          40 :         intern = Z_REFLECTION_P(object);
    1281          40 :         reference = (type_reference*) emalloc(sizeof(type_reference));
    1282          40 :         reference->arg_info = arg_info;
    1283          40 :         reference->fptr = fptr;
    1284          40 :         intern->ptr = reference;
    1285          40 :         intern->ref_type = REF_TYPE_TYPE;
    1286          40 :         intern->ce = fptr->common.scope;
    1287          40 :         if (closure_object) {
    1288             :                 Z_ADDREF_P(closure_object);
    1289          18 :                 ZVAL_COPY_VALUE(&intern->obj, closure_object);
    1290             :         }
    1291          40 : }
    1292             : /* }}} */
    1293             : 
    1294             : /* {{{ reflection_function_factory */
    1295        1068 : static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object)
    1296             : {
    1297             :         reflection_object *intern;
    1298             :         zval name;
    1299             : 
    1300        1068 :         ZVAL_STR_COPY(&name, function->common.function_name);
    1301             : 
    1302        1068 :         reflection_instantiate(reflection_function_ptr, object);
    1303        1068 :         intern = Z_REFLECTION_P(object);
    1304        1068 :         intern->ptr = function;
    1305        1068 :         intern->ref_type = REF_TYPE_FUNCTION;
    1306        1068 :         intern->ce = NULL;
    1307        1068 :         if (closure_object) {
    1308             :                 Z_ADDREF_P(closure_object);
    1309           5 :                 ZVAL_COPY_VALUE(&intern->obj, closure_object);
    1310             :         }
    1311        3204 :         reflection_update_property(object, "name", &name);
    1312        1068 : }
    1313             : /* }}} */
    1314             : 
    1315             : /* {{{ reflection_method_factory */
    1316         323 : static void reflection_method_factory(zend_class_entry *ce, zend_function *method, zval *closure_object, zval *object)
    1317             : {
    1318             :         reflection_object *intern;
    1319             :         zval name;
    1320             :         zval classname;
    1321             : 
    1322         323 :         ZVAL_STR_COPY(&name, (method->common.scope && method->common.scope->trait_aliases)?
    1323             :                         zend_resolve_method_name(ce, method) : method->common.function_name);
    1324         323 :         ZVAL_STR_COPY(&classname, method->common.scope->name);
    1325         323 :         reflection_instantiate(reflection_method_ptr, object);
    1326         323 :         intern = Z_REFLECTION_P(object);
    1327         323 :         intern->ptr = method;
    1328         323 :         intern->ref_type = REF_TYPE_FUNCTION;
    1329         323 :         intern->ce = ce;
    1330         323 :         if (closure_object) {
    1331             :                 Z_ADDREF_P(closure_object);
    1332           0 :                 ZVAL_COPY_VALUE(&intern->obj, closure_object);
    1333             :         }
    1334         969 :         reflection_update_property(object, "name", &name);
    1335         969 :         reflection_update_property(object, "class", &classname);
    1336         323 : }
    1337             : /* }}} */
    1338             : 
    1339             : /* {{{ reflection_property_factory */
    1340         156 : static void reflection_property_factory(zend_class_entry *ce, zend_property_info *prop, zval *object)
    1341             : {
    1342             :         reflection_object *intern;
    1343             :         zval name;
    1344             :         zval classname;
    1345             :         property_reference *reference;
    1346             :         const char *class_name, *prop_name;
    1347             :         size_t prop_name_len;
    1348             : 
    1349         156 :         zend_unmangle_property_name_ex(prop->name, &class_name, &prop_name, &prop_name_len);
    1350             : 
    1351         156 :         if (!(prop->flags & ZEND_ACC_PRIVATE)) {
    1352             :                 /* we have to search the class hierarchy for this (implicit) public or protected property */
    1353         126 :                 zend_class_entry *tmp_ce = ce, *store_ce = ce;
    1354         126 :                 zend_property_info *tmp_info = NULL;
    1355             : 
    1356         399 :                 while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) == NULL) {
    1357          18 :                         ce = tmp_ce;
    1358          18 :                         tmp_ce = tmp_ce->parent;
    1359             :                 }
    1360             : 
    1361         236 :                 if (tmp_info && !(tmp_info->flags & ZEND_ACC_SHADOW)) { /* found something and it's not a parent's private */
    1362         110 :                         prop = tmp_info;
    1363             :                 } else { /* not found, use initial value */
    1364          16 :                         ce = store_ce;
    1365             :                 }
    1366             :         }
    1367             : 
    1368         312 :         ZVAL_STRINGL(&name, prop_name, prop_name_len);
    1369         156 :         ZVAL_STR_COPY(&classname, prop->ce->name);
    1370             : 
    1371         156 :         reflection_instantiate(reflection_property_ptr, object);
    1372         156 :         intern = Z_REFLECTION_P(object);
    1373         156 :         reference = (property_reference*) emalloc(sizeof(property_reference));
    1374         156 :         reference->ce = ce;
    1375         156 :         reference->prop = *prop;
    1376         156 :         intern->ptr = reference;
    1377         156 :         intern->ref_type = REF_TYPE_PROPERTY;
    1378         156 :         intern->ce = ce;
    1379         156 :         intern->ignore_visibility = 0;
    1380         468 :         reflection_update_property(object, "name", &name);
    1381         468 :         reflection_update_property(object, "class", &classname);
    1382         156 : }
    1383             : /* }}} */
    1384             : 
    1385             : /* {{{ reflection_class_constant_factory */
    1386           6 : static void reflection_class_constant_factory(zend_class_entry *ce, zend_string *name_str, zend_class_constant *constant, zval *object)
    1387             : {
    1388             :         reflection_object *intern;
    1389             :         zval name;
    1390             :         zval classname;
    1391             : 
    1392           6 :         ZVAL_STR_COPY(&name, name_str);
    1393           6 :         ZVAL_STR_COPY(&classname, ce->name);
    1394             : 
    1395           6 :         reflection_instantiate(reflection_class_constant_ptr, object);
    1396           6 :         intern = Z_REFLECTION_P(object);
    1397           6 :         intern->ptr = constant;
    1398           6 :         intern->ref_type = REF_TYPE_CLASS_CONSTANT;
    1399           6 :         intern->ce = constant->ce;
    1400           6 :         intern->ignore_visibility = 0;
    1401          18 :         reflection_update_property(object, "name", &name);
    1402          18 :         reflection_update_property(object, "class", &classname);
    1403           6 : }
    1404             : /* }}} */
    1405             : 
    1406             : /* {{{ _reflection_export */
    1407          57 : static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *ce_ptr, int ctor_argc)
    1408             : {
    1409             :         zval reflector;
    1410             :         zval *argument_ptr, *argument2_ptr;
    1411             :         zval retval, params[2];
    1412             :         int result;
    1413          57 :         int return_output = 0;
    1414             :         zend_fcall_info fci;
    1415             :         zend_fcall_info_cache fcc;
    1416             : 
    1417          57 :         if (ctor_argc == 1) {
    1418          19 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &argument_ptr, &return_output) == FAILURE) {
    1419           0 :                         return;
    1420             :                 }
    1421          19 :                 ZVAL_COPY_VALUE(&params[0], argument_ptr);
    1422          19 :                 ZVAL_NULL(&params[1]);
    1423             :         } else {
    1424          38 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz|b", &argument_ptr, &argument2_ptr, &return_output) == FAILURE) {
    1425           4 :                         return;
    1426             :                 }
    1427          34 :                 ZVAL_COPY_VALUE(&params[0], argument_ptr);
    1428          34 :                 ZVAL_COPY_VALUE(&params[1], argument2_ptr);
    1429             :         }
    1430             : 
    1431             :         /* Create object */
    1432          53 :         if (object_and_properties_init(&reflector, ce_ptr, NULL) == FAILURE) {
    1433           0 :                 _DO_THROW("Could not create reflector");
    1434             :         }
    1435             : 
    1436             :         /* Call __construct() */
    1437             : 
    1438          53 :         fci.size = sizeof(fci);
    1439          53 :         ZVAL_UNDEF(&fci.function_name);
    1440          53 :         fci.object = Z_OBJ(reflector);
    1441          53 :         fci.retval = &retval;
    1442          53 :         fci.param_count = ctor_argc;
    1443          53 :         fci.params = params;
    1444          53 :         fci.no_separation = 1;
    1445             : 
    1446          53 :         fcc.initialized = 1;
    1447          53 :         fcc.function_handler = ce_ptr->constructor;
    1448          53 :         fcc.calling_scope = ce_ptr;
    1449          53 :         fcc.called_scope = Z_OBJCE(reflector);
    1450          53 :         fcc.object = Z_OBJ(reflector);
    1451             : 
    1452          53 :         result = zend_call_function(&fci, &fcc);
    1453             : 
    1454          53 :         zval_ptr_dtor(&retval);
    1455             : 
    1456          53 :         if (EG(exception)) {
    1457           7 :                 zval_ptr_dtor(&reflector);
    1458           7 :                 return;
    1459             :         }
    1460          46 :         if (result == FAILURE) {
    1461           0 :                 zval_ptr_dtor(&reflector);
    1462           0 :                 _DO_THROW("Could not create reflector");
    1463             :         }
    1464             : 
    1465             :         /* Call static reflection::export */
    1466          46 :         ZVAL_COPY_VALUE(&params[0], &reflector);
    1467          46 :         ZVAL_BOOL(&params[1], return_output);
    1468             : 
    1469          92 :         ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1);
    1470          46 :         fci.object = NULL;
    1471          46 :         fci.retval = &retval;
    1472          46 :         fci.param_count = 2;
    1473          46 :         fci.params = params;
    1474          46 :         fci.no_separation = 1;
    1475             : 
    1476          46 :         result = zend_call_function(&fci, NULL);
    1477             : 
    1478          46 :         zval_ptr_dtor(&fci.function_name);
    1479             : 
    1480          46 :         if (result == FAILURE && EG(exception) == NULL) {
    1481           0 :                 zval_ptr_dtor(&reflector);
    1482           0 :                 zval_ptr_dtor(&retval);
    1483           0 :                 _DO_THROW("Could not execute reflection::export()");
    1484             :         }
    1485             : 
    1486          46 :         if (return_output) {
    1487          17 :                 ZVAL_COPY_VALUE(return_value, &retval);
    1488             :         } else {
    1489          29 :                 zval_ptr_dtor(&retval);
    1490             :         }
    1491             : 
    1492             :         /* Destruct reflector which is no longer needed */
    1493          46 :         zval_ptr_dtor(&reflector);
    1494             : }
    1495             : /* }}} */
    1496             : 
    1497             : /* {{{ _reflection_param_get_default_param */
    1498          42 : static parameter_reference *_reflection_param_get_default_param(INTERNAL_FUNCTION_PARAMETERS)
    1499             : {
    1500             :         reflection_object *intern;
    1501             :         parameter_reference *param;
    1502             : 
    1503          84 :         intern = Z_REFLECTION_P(getThis());
    1504          42 :         if (intern->ptr == NULL) {
    1505           0 :                 if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) {
    1506           0 :                         return NULL;
    1507             :                 }
    1508           0 :                 zend_throw_error(NULL, "Internal error: Failed to retrieve the reflection object");
    1509           0 :                 return NULL;
    1510             :         }
    1511             : 
    1512          42 :         param = intern->ptr;
    1513          42 :         if (param->fptr->type != ZEND_USER_FUNCTION) {
    1514           0 :                 zend_throw_exception_ex(reflection_exception_ptr, 0, "Cannot determine default value for internal functions");
    1515           0 :                 return NULL;
    1516             :         }
    1517             : 
    1518          42 :         return param;
    1519             : }
    1520             : /* }}} */
    1521             : 
    1522             : /* {{{ _reflection_param_get_default_precv */
    1523          42 : static zend_op *_reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAMETERS, parameter_reference *param)
    1524             : {
    1525             :         zend_op *precv;
    1526             : 
    1527          42 :         if (param == NULL) {
    1528           0 :                 return NULL;
    1529             :         }
    1530             : 
    1531          42 :         precv = _get_recv_op((zend_op_array*)param->fptr, param->offset);
    1532          42 :         if (!precv || precv->opcode != ZEND_RECV_INIT || precv->op2_type == IS_UNUSED) {
    1533           1 :                 zend_throw_exception_ex(reflection_exception_ptr, 0, "Internal error: Failed to retrieve the default value");
    1534           1 :                 return NULL;
    1535             :         }
    1536             : 
    1537          41 :         return precv;
    1538             : }
    1539             : /* }}} */
    1540             : 
    1541             : /* {{{ Preventing __clone from being called */
    1542           0 : ZEND_METHOD(reflection, __clone)
    1543             : {
    1544             :         /* Should never be executable */
    1545           0 :         _DO_THROW("Cannot clone object using __clone()");
    1546             : }
    1547             : /* }}} */
    1548             : 
    1549             : /* {{{ proto public static mixed Reflection::export(Reflector r [, bool return])
    1550             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    1551         188 : ZEND_METHOD(reflection, export)
    1552             : {
    1553             :         zval *object, fname, retval;
    1554             :         int result;
    1555         188 :         zend_bool return_output = 0;
    1556             : 
    1557             : #ifndef FAST_ZPP
    1558             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &object, reflector_ptr, &return_output) == FAILURE) {
    1559             :                 return;
    1560             :         }
    1561             : #else
    1562         188 :         ZEND_PARSE_PARAMETERS_START(1, 2)
    1563         564 :                 Z_PARAM_OBJECT_OF_CLASS(object, reflector_ptr)
    1564         188 :                 Z_PARAM_OPTIONAL
    1565         280 :                 Z_PARAM_BOOL(return_output)
    1566         188 :         ZEND_PARSE_PARAMETERS_END();
    1567             : #endif
    1568             : 
    1569             :         /* Invoke the __toString() method */
    1570         376 :         ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1);
    1571         188 :         result= call_user_function_ex(NULL, object, &fname, &retval, 0, NULL, 0, NULL);
    1572             :         zval_dtor(&fname);
    1573             : 
    1574         188 :         if (result == FAILURE) {
    1575           0 :                 _DO_THROW("Invocation of method __toString() failed");
    1576             :                 /* Returns from this function */
    1577             :         }
    1578             : 
    1579         188 :         if (Z_TYPE(retval) == IS_UNDEF) {
    1580           0 :                 php_error_docref(NULL, E_WARNING, "%s::__toString() did not return anything", ZSTR_VAL(Z_OBJCE_P(object)->name));
    1581           0 :                 RETURN_FALSE;
    1582             :         }
    1583             : 
    1584         188 :         if (return_output) {
    1585          17 :                 ZVAL_COPY_VALUE(return_value, &retval);
    1586             :         } else {
    1587             :                 /* No need for _r variant, return of __toString should always be a string */
    1588         171 :                 zend_print_zval(&retval, 0);
    1589         171 :                 zend_printf("\n");
    1590         171 :                 zval_ptr_dtor(&retval);
    1591             :         }
    1592             : }
    1593             : /* }}} */
    1594             : 
    1595             : /* {{{ proto public static array Reflection::getModifierNames(int modifiers)
    1596             :    Returns an array of modifier names */
    1597          18 : ZEND_METHOD(reflection, getModifierNames)
    1598             : {
    1599             :         zend_long modifiers;
    1600             : 
    1601          18 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &modifiers) == FAILURE) {
    1602           0 :                 return;
    1603             :         }
    1604             : 
    1605          18 :         array_init(return_value);
    1606             : 
    1607          18 :         if (modifiers & (ZEND_ACC_ABSTRACT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
    1608           3 :                 add_next_index_stringl(return_value, "abstract", sizeof("abstract")-1);
    1609             :         }
    1610          18 :         if (modifiers & ZEND_ACC_FINAL) {
    1611           3 :                 add_next_index_stringl(return_value, "final", sizeof("final")-1);
    1612             :         }
    1613          18 :         if (modifiers & ZEND_ACC_IMPLICIT_PUBLIC) {
    1614           1 :                 add_next_index_stringl(return_value, "public", sizeof("public")-1);
    1615             :         }
    1616             : 
    1617             :         /* These are mutually exclusive */
    1618          18 :         switch (modifiers & ZEND_ACC_PPP_MASK) {
    1619             :                 case ZEND_ACC_PUBLIC:
    1620           7 :                         add_next_index_stringl(return_value, "public", sizeof("public")-1);
    1621           7 :                         break;
    1622             :                 case ZEND_ACC_PRIVATE:
    1623           2 :                         add_next_index_stringl(return_value, "private", sizeof("private")-1);
    1624           2 :                         break;
    1625             :                 case ZEND_ACC_PROTECTED:
    1626           4 :                         add_next_index_stringl(return_value, "protected", sizeof("protected")-1);
    1627             :                         break;
    1628             :         }
    1629             : 
    1630          18 :         if (modifiers & ZEND_ACC_STATIC) {
    1631           3 :                 add_next_index_stringl(return_value, "static", sizeof("static")-1);
    1632             :         }
    1633             : }
    1634             : /* }}} */
    1635             : 
    1636             : /* {{{ proto public static mixed ReflectionFunction::export(string name [, bool return])
    1637             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    1638           2 : ZEND_METHOD(reflection_function, export)
    1639             : {
    1640           2 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_function_ptr, 1);
    1641           2 : }
    1642             : /* }}} */
    1643             : 
    1644             : /* {{{ proto public void ReflectionFunction::__construct(string name)
    1645             :    Constructor. Throws an Exception in case the given function does not exist */
    1646         401 : ZEND_METHOD(reflection_function, __construct)
    1647             : {
    1648             :         zval name;
    1649             :         zval *object;
    1650         401 :         zval *closure = NULL;
    1651             :         char *lcname, *nsname;
    1652             :         reflection_object *intern;
    1653             :         zend_function *fptr;
    1654             :         char *name_str;
    1655             :         size_t name_len;
    1656             : 
    1657         802 :         object = getThis();
    1658         401 :         intern = Z_REFLECTION_P(object);
    1659             : 
    1660         401 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == SUCCESS) {
    1661          30 :                 fptr = (zend_function*)zend_get_closure_method_def(closure);
    1662          30 :                 Z_ADDREF_P(closure);
    1663             :         } else { 
    1664         371 :                 if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
    1665           4 :                         return;
    1666             :                 }
    1667             : 
    1668         367 :                 lcname = zend_str_tolower_dup(name_str, name_len);
    1669             : 
    1670             :                 /* Ignore leading "\" */
    1671         367 :                 nsname = lcname;
    1672         367 :                 if (lcname[0] == '\\') {
    1673           1 :                         nsname = &lcname[1];
    1674           1 :                         name_len--;
    1675             :                 }
    1676             : 
    1677         734 :                 if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) {
    1678           3 :                         efree(lcname);
    1679           3 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    1680             :                                 "Function %s() does not exist", name_str);
    1681           3 :                         return;
    1682             :                 }
    1683         364 :                 efree(lcname);
    1684             :         }
    1685             : 
    1686         394 :         ZVAL_STR_COPY(&name, fptr->common.function_name);
    1687        1182 :         reflection_update_property(object, "name", &name);
    1688         394 :         intern->ptr = fptr;
    1689         394 :         intern->ref_type = REF_TYPE_FUNCTION;
    1690         394 :         if (closure) {
    1691          30 :                 ZVAL_COPY_VALUE(&intern->obj, closure);
    1692             :         } else {
    1693         364 :                 ZVAL_UNDEF(&intern->obj);
    1694             :         }
    1695         394 :         intern->ce = NULL;
    1696             : }
    1697             : /* }}} */
    1698             : 
    1699             : /* {{{ proto public string ReflectionFunction::__toString()
    1700             :    Returns a string representation */
    1701         128 : ZEND_METHOD(reflection_function, __toString)
    1702             : {
    1703             :         reflection_object *intern;
    1704             :         zend_function *fptr;
    1705             :         string str;
    1706             : 
    1707         128 :         if (zend_parse_parameters_none() == FAILURE) {
    1708           0 :                 return;
    1709             :         }
    1710         256 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1711         128 :         string_init(&str);
    1712         128 :         _function_string(&str, fptr, intern->ce, "");
    1713         128 :         RETURN_NEW_STR(str.buf);
    1714             : }
    1715             : /* }}} */
    1716             : 
    1717             : /* {{{ proto public string ReflectionFunction::getName()
    1718             :    Returns this function's name */
    1719         276 : ZEND_METHOD(reflection_function, getName)
    1720             : {
    1721         276 :         if (zend_parse_parameters_none() == FAILURE) {
    1722           1 :                 return;
    1723             :         }
    1724         550 :         _default_get_entry(getThis(), "name", sizeof("name")-1, return_value);
    1725             : }
    1726             : /* }}} */
    1727             : 
    1728             : /* {{{ proto public bool ReflectionFunction::isClosure()
    1729             :    Returns whether this is a closure */
    1730           2 : ZEND_METHOD(reflection_function, isClosure)
    1731             : {
    1732             :         reflection_object *intern;
    1733             :         zend_function *fptr;
    1734             : 
    1735           2 :         if (zend_parse_parameters_none() == FAILURE) {
    1736           0 :                 return;
    1737             :         }
    1738           4 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1739           2 :         RETURN_BOOL(fptr->common.fn_flags & ZEND_ACC_CLOSURE);
    1740             : }
    1741             : /* }}} */
    1742             : 
    1743             : /* {{{ proto public bool ReflectionFunction::getClosureThis()
    1744             :    Returns this pointer bound to closure */
    1745           3 : ZEND_METHOD(reflection_function, getClosureThis)
    1746             : {
    1747             :         reflection_object *intern;
    1748             :         zval* closure_this;
    1749             : 
    1750           3 :         if (zend_parse_parameters_none() == FAILURE) {
    1751           0 :                 return;
    1752             :         }
    1753           6 :         GET_REFLECTION_OBJECT();
    1754           6 :         if (!Z_ISUNDEF(intern->obj)) {
    1755           3 :                 closure_this = zend_get_closure_this_ptr(&intern->obj);
    1756           3 :                 if (!Z_ISUNDEF_P(closure_this)) {
    1757           1 :                         ZVAL_COPY(return_value, closure_this);
    1758             :                 }
    1759             :         }
    1760             : }
    1761             : /* }}} */
    1762             : 
    1763             : /* {{{ proto public ReflectionClass ReflectionFunction::getClosureScopeClass()
    1764             :    Returns the scope associated to the closure */
    1765           4 : ZEND_METHOD(reflection_function, getClosureScopeClass)
    1766             : {
    1767             :         reflection_object *intern;
    1768             :         const zend_function *closure_func;
    1769             : 
    1770           4 :         if (zend_parse_parameters_none() == FAILURE) {
    1771           0 :                 return;
    1772             :         }
    1773           8 :         GET_REFLECTION_OBJECT();
    1774           8 :         if (!Z_ISUNDEF(intern->obj)) {
    1775           4 :                 closure_func = zend_get_closure_method_def(&intern->obj);
    1776           4 :                 if (closure_func && closure_func->common.scope) {
    1777           3 :                         zend_reflection_class_factory(closure_func->common.scope, return_value);
    1778             :                 }
    1779             :         }
    1780             : }
    1781             : /* }}} */
    1782             : 
    1783             : /* {{{ proto public mixed ReflectionFunction::getClosure()
    1784             :    Returns a dynamically created closure for the function */
    1785          11 : ZEND_METHOD(reflection_function, getClosure)
    1786             : {
    1787             :         reflection_object *intern;
    1788             :         zend_function *fptr;
    1789             : 
    1790          11 :         if (zend_parse_parameters_none() == FAILURE) {
    1791           1 :                 return;
    1792             :         }
    1793          20 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1794             : 
    1795          20 :         if (!Z_ISUNDEF(intern->obj)) {
    1796             :                 /* Closures are immutable objects */
    1797           2 :                 ZVAL_COPY(return_value, &intern->obj);
    1798             :         } else {
    1799           8 :                 zend_create_fake_closure(return_value, fptr, NULL, NULL, NULL);
    1800             :         }
    1801             : }
    1802             : /* }}} */
    1803             : 
    1804             : /* {{{ proto public bool ReflectionFunction::isInternal()
    1805             :    Returns whether this is an internal function */
    1806          76 : ZEND_METHOD(reflection_function, isInternal)
    1807             : {
    1808             :         reflection_object *intern;
    1809             :         zend_function *fptr;
    1810             : 
    1811          76 :         if (zend_parse_parameters_none() == FAILURE) {
    1812           1 :                 return;
    1813             :         }
    1814         150 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1815          75 :         RETURN_BOOL(fptr->type == ZEND_INTERNAL_FUNCTION);
    1816             : }
    1817             : /* }}} */
    1818             : 
    1819             : /* {{{ proto public bool ReflectionFunction::isUserDefined()
    1820             :    Returns whether this is a user-defined function */
    1821          76 : ZEND_METHOD(reflection_function, isUserDefined)
    1822             : {
    1823             :         reflection_object *intern;
    1824             :         zend_function *fptr;
    1825             : 
    1826          76 :         if (zend_parse_parameters_none() == FAILURE) {
    1827           1 :                 return;
    1828             :         }
    1829         150 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1830          75 :         RETURN_BOOL(fptr->type == ZEND_USER_FUNCTION);
    1831             : }
    1832             : /* }}} */
    1833             : 
    1834             : /* {{{ proto public bool ReflectionFunction::isDisabled()
    1835             :    Returns whether this function has been disabled or not */
    1836           1 : ZEND_METHOD(reflection_function, isDisabled)
    1837             : {
    1838             :         reflection_object *intern;
    1839             :         zend_function *fptr;
    1840             : 
    1841           2 :         METHOD_NOTSTATIC(reflection_function_ptr);
    1842           2 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1843           1 :         RETURN_BOOL(fptr->type == ZEND_INTERNAL_FUNCTION && fptr->internal_function.handler == zif_display_disabled_function);
    1844             : }
    1845             : /* }}} */
    1846             : 
    1847             : /* {{{ proto public string ReflectionFunction::getFileName()
    1848             :    Returns the filename of the file this function was declared in */
    1849          15 : ZEND_METHOD(reflection_function, getFileName)
    1850             : {
    1851             :         reflection_object *intern;
    1852             :         zend_function *fptr;
    1853             : 
    1854          15 :         if (zend_parse_parameters_none() == FAILURE) {
    1855           1 :                 return;
    1856             :         }
    1857          28 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1858          14 :         if (fptr->type == ZEND_USER_FUNCTION) {
    1859          12 :                 RETURN_STR_COPY(fptr->op_array.filename);
    1860             :         }
    1861           2 :         RETURN_FALSE;
    1862             : }
    1863             : /* }}} */
    1864             : 
    1865             : /* {{{ proto public int ReflectionFunction::getStartLine()
    1866             :    Returns the line this function's declaration starts at */
    1867          14 : ZEND_METHOD(reflection_function, getStartLine)
    1868             : {
    1869             :         reflection_object *intern;
    1870             :         zend_function *fptr;
    1871             : 
    1872          14 :         if (zend_parse_parameters_none() == FAILURE) {
    1873           1 :                 return;
    1874             :         }
    1875          26 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1876          13 :         if (fptr->type == ZEND_USER_FUNCTION) {
    1877          11 :                 RETURN_LONG(fptr->op_array.line_start);
    1878             :         }
    1879           2 :         RETURN_FALSE;
    1880             : }
    1881             : /* }}} */
    1882             : 
    1883             : /* {{{ proto public int ReflectionFunction::getEndLine()
    1884             :    Returns the line this function's declaration ends at */
    1885          14 : ZEND_METHOD(reflection_function, getEndLine)
    1886             : {
    1887             :         reflection_object *intern;
    1888             :         zend_function *fptr;
    1889             : 
    1890          14 :         if (zend_parse_parameters_none() == FAILURE) {
    1891           1 :                 return;
    1892             :         }
    1893          26 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1894          13 :         if (fptr->type == ZEND_USER_FUNCTION) {
    1895          11 :                 RETURN_LONG(fptr->op_array.line_end);
    1896             :         }
    1897           2 :         RETURN_FALSE;
    1898             : }
    1899             : /* }}} */
    1900             : 
    1901             : /* {{{ proto public string ReflectionFunction::getDocComment()
    1902             :    Returns the doc comment for this function */
    1903          24 : ZEND_METHOD(reflection_function, getDocComment)
    1904             : {
    1905             :         reflection_object *intern;
    1906             :         zend_function *fptr;
    1907             : 
    1908          24 :         if (zend_parse_parameters_none() == FAILURE) {
    1909           2 :                 return;
    1910             :         }
    1911          44 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1912          22 :         if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
    1913          15 :                 RETURN_STR_COPY(fptr->op_array.doc_comment);
    1914             :         }
    1915           7 :         RETURN_FALSE;
    1916             : }
    1917             : /* }}} */
    1918             : 
    1919             : /* {{{ proto public array ReflectionFunction::getStaticVariables()
    1920             :    Returns an associative array containing this function's static variables and their values */
    1921          75 : ZEND_METHOD(reflection_function, getStaticVariables)
    1922             : {
    1923             :         reflection_object *intern;
    1924             :         zend_function *fptr;
    1925             :         zval *val;
    1926             : 
    1927          75 :         if (zend_parse_parameters_none() == FAILURE) {
    1928           1 :                 return;
    1929             :         }
    1930         148 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1931             : 
    1932             :         /* Return an empty array in case no static variables exist */
    1933          74 :         array_init(return_value);
    1934          74 :         if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.static_variables != NULL) {
    1935           8 :                 if (GC_REFCOUNT(fptr->op_array.static_variables) > 1) {
    1936           0 :                         if (!(GC_FLAGS(fptr->op_array.static_variables) & IS_ARRAY_IMMUTABLE)) {
    1937           0 :                                 GC_REFCOUNT(fptr->op_array.static_variables)--;
    1938             :                         }
    1939           0 :                         fptr->op_array.static_variables = zend_array_dup(fptr->op_array.static_variables);
    1940             :                 }
    1941          32 :                 ZEND_HASH_FOREACH_VAL(fptr->op_array.static_variables, val) {
    1942          12 :                         if (UNEXPECTED(zval_update_constant_ex(val, fptr->common.scope) != SUCCESS)) {
    1943           0 :                                 return;
    1944             :                         }
    1945             :                 } ZEND_HASH_FOREACH_END();
    1946           8 :                 zend_hash_copy(Z_ARRVAL_P(return_value), fptr->op_array.static_variables, zval_add_ref);
    1947             :         }
    1948             : }
    1949             : /* }}} */
    1950             : 
    1951             : /* {{{ proto public mixed ReflectionFunction::invoke([mixed* args])
    1952             :    Invokes the function */
    1953           4 : ZEND_METHOD(reflection_function, invoke)
    1954             : {
    1955             :         zval retval;
    1956           4 :         zval *params = NULL;
    1957           4 :         int result, num_args = 0;
    1958             :         zend_fcall_info fci;
    1959             :         zend_fcall_info_cache fcc;
    1960             :         reflection_object *intern;
    1961             :         zend_function *fptr;
    1962             : 
    1963           8 :         METHOD_NOTSTATIC(reflection_function_ptr);
    1964           8 :         GET_REFLECTION_OBJECT_PTR(fptr);
    1965             : 
    1966           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &params, &num_args) == FAILURE) {
    1967           0 :                 return;
    1968             :         }
    1969             : 
    1970           4 :         fci.size = sizeof(fci);
    1971           4 :         ZVAL_UNDEF(&fci.function_name);
    1972           4 :         fci.object = NULL;
    1973           4 :         fci.retval = &retval;
    1974           4 :         fci.param_count = num_args;
    1975           4 :         fci.params = params;
    1976           4 :         fci.no_separation = 1;
    1977             : 
    1978           4 :         fcc.initialized = 1;
    1979           4 :         fcc.function_handler = fptr;
    1980           4 :         fcc.calling_scope = zend_get_executed_scope();
    1981           4 :         fcc.called_scope = NULL;
    1982           4 :         fcc.object = NULL;
    1983             : 
    1984           4 :         result = zend_call_function(&fci, &fcc);
    1985             : 
    1986           4 :         if (result == FAILURE) {
    1987           0 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    1988           0 :                         "Invocation of function %s() failed", ZSTR_VAL(fptr->common.function_name));
    1989           0 :                 return;
    1990             :         }
    1991             : 
    1992           4 :         if (Z_TYPE(retval) != IS_UNDEF) {
    1993           4 :                 ZVAL_COPY_VALUE(return_value, &retval);
    1994             :         }
    1995             : }
    1996             : /* }}} */
    1997             : 
    1998             : /* {{{ proto public mixed ReflectionFunction::invokeArgs(array args)
    1999             :    Invokes the function and pass its arguments as array. */
    2000           3 : ZEND_METHOD(reflection_function, invokeArgs)
    2001             : {
    2002             :         zval retval;
    2003             :         zval *params, *val;
    2004             :         int result;
    2005             :         int i, argc;
    2006             :         zend_fcall_info fci;
    2007             :         zend_fcall_info_cache fcc;
    2008             :         reflection_object *intern;
    2009             :         zend_function *fptr;
    2010             :         zval *param_array;
    2011             : 
    2012           6 :         METHOD_NOTSTATIC(reflection_function_ptr);
    2013           6 :         GET_REFLECTION_OBJECT_PTR(fptr);
    2014             : 
    2015           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &param_array) == FAILURE) {
    2016           0 :                 return;
    2017             :         }
    2018             : 
    2019           3 :         argc = zend_hash_num_elements(Z_ARRVAL_P(param_array));
    2020             : 
    2021           3 :         params = safe_emalloc(sizeof(zval), argc, 0);
    2022           3 :         argc = 0;
    2023          17 :         ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(param_array), val) {
    2024           7 :                 ZVAL_COPY(&params[argc], val);
    2025           7 :                 argc++;
    2026             :         } ZEND_HASH_FOREACH_END();
    2027             : 
    2028           3 :         fci.size = sizeof(fci);
    2029           3 :         ZVAL_UNDEF(&fci.function_name);
    2030           3 :         fci.object = NULL;
    2031           3 :         fci.retval = &retval;
    2032           3 :         fci.param_count = argc;
    2033           3 :         fci.params = params;
    2034           3 :         fci.no_separation = 1;
    2035             : 
    2036           3 :         fcc.initialized = 1;
    2037           3 :         fcc.function_handler = fptr;
    2038           3 :         fcc.calling_scope = zend_get_executed_scope();
    2039           3 :         fcc.called_scope = NULL;
    2040           3 :         fcc.object = NULL;
    2041             : 
    2042           3 :         result = zend_call_function(&fci, &fcc);
    2043             : 
    2044          10 :         for (i = 0; i < argc; i++) {
    2045           7 :                 zval_ptr_dtor(&params[i]);
    2046             :         }
    2047           3 :         efree(params);
    2048             : 
    2049           3 :         if (result == FAILURE) {
    2050           0 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    2051           0 :                         "Invocation of function %s() failed", ZSTR_VAL(fptr->common.function_name));
    2052           0 :                 return;
    2053             :         }
    2054             : 
    2055           3 :         if (Z_TYPE(retval) != IS_UNDEF) {
    2056           3 :                 ZVAL_COPY_VALUE(return_value, &retval);
    2057             :         }
    2058             : }
    2059             : /* }}} */
    2060             : 
    2061             : /* {{{ proto public bool ReflectionFunction::returnsReference()
    2062             :    Gets whether this function returns a reference */
    2063          66 : ZEND_METHOD(reflection_function, returnsReference)
    2064             : {
    2065             :         reflection_object *intern;
    2066             :         zend_function *fptr;
    2067             : 
    2068         132 :         METHOD_NOTSTATIC(reflection_function_abstract_ptr);
    2069         132 :         GET_REFLECTION_OBJECT_PTR(fptr);
    2070             : 
    2071          66 :         RETURN_BOOL((fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0);
    2072             : }
    2073             : /* }}} */
    2074             : 
    2075             : /* {{{ proto public bool ReflectionFunction::getNumberOfParameters()
    2076             :    Gets the number of required parameters */
    2077          69 : ZEND_METHOD(reflection_function, getNumberOfParameters)
    2078             : {
    2079             :         reflection_object *intern;
    2080             :         zend_function *fptr;
    2081             :         uint32_t num_args;
    2082             : 
    2083         138 :         METHOD_NOTSTATIC(reflection_function_abstract_ptr);
    2084         138 :         GET_REFLECTION_OBJECT_PTR(fptr);
    2085             : 
    2086          69 :         num_args = fptr->common.num_args;
    2087          69 :         if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) {
    2088           0 :                 num_args++;
    2089             :         }
    2090             : 
    2091          69 :         RETURN_LONG(num_args);
    2092             : }
    2093             : /* }}} */
    2094             : 
    2095             : /* {{{ proto public bool ReflectionFunction::getNumberOfRequiredParameters()
    2096             :    Gets the number of required parameters */
    2097         238 : ZEND_METHOD(reflection_function, getNumberOfRequiredParameters)
    2098             : {
    2099             :         reflection_object *intern;
    2100             :         zend_function *fptr;
    2101             : 
    2102         476 :         METHOD_NOTSTATIC(reflection_function_abstract_ptr);
    2103         476 :         GET_REFLECTION_OBJECT_PTR(fptr);
    2104             : 
    2105         238 :         RETURN_LONG(fptr->common.required_num_args);
    2106             : }
    2107             : /* }}} */
    2108             : 
    2109             : /* {{{ proto public ReflectionParameter[] ReflectionFunction::getParameters()
    2110             :    Returns an array of parameter objects for this function */
    2111         132 : ZEND_METHOD(reflection_function, getParameters)
    2112             : {
    2113             :         reflection_object *intern;
    2114             :         zend_function *fptr;
    2115             :         uint32_t i, num_args;
    2116             :         struct _zend_arg_info *arg_info;
    2117             : 
    2118         264 :         METHOD_NOTSTATIC(reflection_function_abstract_ptr);
    2119         264 :         GET_REFLECTION_OBJECT_PTR(fptr);
    2120             : 
    2121         132 :         arg_info= fptr->common.arg_info;
    2122         132 :         num_args = fptr->common.num_args;
    2123         132 :         if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) {
    2124           5 :                 num_args++;
    2125             :         }
    2126             : 
    2127         132 :         array_init(return_value);
    2128         378 :         for (i = 0; i < num_args; i++) {
    2129             :                 zval parameter;
    2130             : 
    2131         492 :                 reflection_parameter_factory(_copy_function(fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, arg_info, i, fptr->common.required_num_args, &parameter);
    2132         246 :                 add_next_index_zval(return_value, &parameter);
    2133             : 
    2134         246 :                 arg_info++;
    2135             :         }
    2136             : }
    2137             : /* }}} */
    2138             : 
    2139             : /* {{{ proto public ReflectionExtension|NULL ReflectionFunction::getExtension()
    2140             :    Returns NULL or the extension the function belongs to */
    2141           2 : ZEND_METHOD(reflection_function, getExtension)
    2142             : {
    2143             :         reflection_object *intern;
    2144             :         zend_function *fptr;
    2145             :         zend_internal_function *internal;
    2146             : 
    2147           4 :         METHOD_NOTSTATIC(reflection_function_abstract_ptr);
    2148           4 :         GET_REFLECTION_OBJECT_PTR(fptr);
    2149             : 
    2150           2 :         if (fptr->type != ZEND_INTERNAL_FUNCTION) {
    2151           1 :                 RETURN_NULL();
    2152             :         }
    2153             : 
    2154           1 :         internal = (zend_internal_function *)fptr;
    2155           1 :         if (internal->module) {
    2156           1 :                 reflection_extension_factory(return_value, internal->module->name);
    2157             :         } else {
    2158           0 :                 RETURN_NULL();
    2159             :         }
    2160             : }
    2161             : /* }}} */
    2162             : 
    2163             : /* {{{ proto public string|false ReflectionFunction::getExtensionName()
    2164             :    Returns false or the name of the extension the function belongs to */
    2165           3 : ZEND_METHOD(reflection_function, getExtensionName)
    2166             : {
    2167             :         reflection_object *intern;
    2168             :         zend_function *fptr;
    2169             :         zend_internal_function *internal;
    2170             : 
    2171           6 :         METHOD_NOTSTATIC(reflection_function_abstract_ptr);
    2172           6 :         GET_REFLECTION_OBJECT_PTR(fptr);
    2173             : 
    2174           3 :         if (fptr->type != ZEND_INTERNAL_FUNCTION) {
    2175           1 :                 RETURN_FALSE;
    2176             :         }
    2177             : 
    2178           2 :         internal = (zend_internal_function *)fptr;
    2179           2 :         if (internal->module) {
    2180           4 :                 RETURN_STRING(internal->module->name);
    2181             :         } else {
    2182           0 :                 RETURN_FALSE;
    2183             :         }
    2184             : }
    2185             : /* }}} */
    2186             : 
    2187             : /* {{{ proto public void ReflectionGenerator::__construct(object Generator) */
    2188           5 : ZEND_METHOD(reflection_generator, __construct)
    2189             : {
    2190             :         zval *generator, *object;
    2191             :         reflection_object *intern;
    2192             :         zend_execute_data *ex;
    2193             : 
    2194          10 :         object = getThis();
    2195           5 :         intern = Z_REFLECTION_P(object);
    2196             : 
    2197           5 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &generator, zend_ce_generator) == FAILURE) {
    2198           0 :                 return;
    2199             :         }
    2200             : 
    2201           5 :         ex = ((zend_generator *) Z_OBJ_P(generator))->execute_data;
    2202           5 :         if (!ex) {
    2203           0 :                 zend_throw_exception(NULL, "Cannot create ReflectionGenerator based on a terminated Generator", 0);
    2204           0 :                 return;
    2205             :         }
    2206             : 
    2207           5 :         intern->ref_type = REF_TYPE_GENERATOR;
    2208           5 :         ZVAL_COPY(&intern->obj, generator);
    2209           5 :         intern->ce = zend_ce_generator;
    2210             : }
    2211             : /* }}} */
    2212             : 
    2213             : #define REFLECTION_CHECK_VALID_GENERATOR(ex) \
    2214             :         if (!ex) { \
    2215             :                 zend_throw_exception(NULL, "Cannot fetch information from a terminated Generator", 0); \
    2216             :                 return; \
    2217             :         }
    2218             : 
    2219             : /* {{{ proto public array ReflectionGenerator::getTrace($options = DEBUG_BACKTRACE_PROVIDE_OBJECT) */
    2220           6 : ZEND_METHOD(reflection_generator, getTrace)
    2221             : {
    2222           6 :         zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT;
    2223          12 :         zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj);
    2224             :         zend_generator *root_generator;
    2225           6 :         zend_execute_data *ex_backup = EG(current_execute_data);
    2226           6 :         zend_execute_data *ex = generator->execute_data;
    2227           6 :         zend_execute_data *root_prev = NULL, *cur_prev;
    2228             : 
    2229           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &options) == FAILURE) {
    2230           0 :                 return;
    2231             :         }
    2232             : 
    2233           6 :         REFLECTION_CHECK_VALID_GENERATOR(ex)
    2234             : 
    2235           6 :         root_generator = zend_generator_get_current(generator);
    2236             : 
    2237           6 :         cur_prev = generator->execute_data->prev_execute_data;
    2238           6 :         if (generator == root_generator) {
    2239           3 :                 generator->execute_data->prev_execute_data = NULL;
    2240             :         } else {
    2241           3 :                 root_prev = root_generator->execute_data->prev_execute_data;
    2242           3 :                 generator->execute_fake.prev_execute_data = NULL;
    2243           3 :                 root_generator->execute_data->prev_execute_data = &generator->execute_fake;
    2244             :         }
    2245             : 
    2246           6 :         EG(current_execute_data) = root_generator->execute_data;
    2247           6 :         zend_fetch_debug_backtrace(return_value, 0, options, 0);
    2248           6 :         EG(current_execute_data) = ex_backup;
    2249             : 
    2250           6 :         root_generator->execute_data->prev_execute_data = root_prev;
    2251           6 :         generator->execute_data->prev_execute_data = cur_prev;
    2252             : }
    2253             : /* }}} */
    2254             : 
    2255             : /* {{{ proto public int ReflectionGenerator::getExecutingLine() */
    2256           5 : ZEND_METHOD(reflection_generator, getExecutingLine)
    2257             : {
    2258          10 :         zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj);
    2259           5 :         zend_execute_data *ex = generator->execute_data;
    2260             : 
    2261           5 :         if (zend_parse_parameters_none() == FAILURE) {
    2262           0 :                 return;
    2263             :         }
    2264             : 
    2265           5 :         REFLECTION_CHECK_VALID_GENERATOR(ex)
    2266             : 
    2267           5 :         ZVAL_LONG(return_value, ex->opline->lineno);
    2268             : }
    2269             : /* }}} */
    2270             : 
    2271             : /* {{{ proto public string ReflectionGenerator::getExecutingFile() */
    2272           5 : ZEND_METHOD(reflection_generator, getExecutingFile)
    2273             : {
    2274          10 :         zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj);
    2275           5 :         zend_execute_data *ex = generator->execute_data;
    2276             : 
    2277           5 :         if (zend_parse_parameters_none() == FAILURE) {
    2278           0 :                 return;
    2279             :         }
    2280             : 
    2281           5 :         REFLECTION_CHECK_VALID_GENERATOR(ex)
    2282             : 
    2283           5 :         ZVAL_STR_COPY(return_value, ex->func->op_array.filename);
    2284             : }
    2285             : /* }}} */
    2286             : 
    2287             : /* {{{ proto public ReflectionFunctionAbstract ReflectionGenerator::getFunction() */
    2288           5 : ZEND_METHOD(reflection_generator, getFunction)
    2289             : {
    2290          10 :         zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj);
    2291           5 :         zend_execute_data *ex = generator->execute_data;
    2292             : 
    2293           5 :         if (zend_parse_parameters_none() == FAILURE) {
    2294           0 :                 return;
    2295             :         }
    2296             : 
    2297           5 :         REFLECTION_CHECK_VALID_GENERATOR(ex)
    2298             : 
    2299           5 :         if (ex->func->common.fn_flags & ZEND_ACC_CLOSURE) {
    2300             :                 zval closure;
    2301           3 :                 ZVAL_OBJ(&closure, (zend_object *) ex->func->common.prototype);
    2302           3 :                 reflection_function_factory(ex->func, &closure, return_value);
    2303           2 :         } else if (ex->func->op_array.scope) {
    2304           1 :                 reflection_method_factory(ex->func->op_array.scope, ex->func, NULL, return_value);
    2305             :         } else {
    2306           1 :                 reflection_function_factory(ex->func, NULL, return_value);
    2307             :         }
    2308             : }
    2309             : /* }}} */
    2310             : 
    2311             : /* {{{ proto public object ReflectionGenerator::getThis() */
    2312           5 : ZEND_METHOD(reflection_generator, getThis)
    2313             : {
    2314          10 :         zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj);
    2315           5 :         zend_execute_data *ex = generator->execute_data;
    2316             : 
    2317           5 :         if (zend_parse_parameters_none() == FAILURE) {
    2318           0 :                 return;
    2319             :         }
    2320             : 
    2321           5 :         REFLECTION_CHECK_VALID_GENERATOR(ex)
    2322             : 
    2323          10 :         if (Z_TYPE(ex->This) == IS_OBJECT) {
    2324           1 :                 ZVAL_COPY(return_value, &ex->This);
    2325             :         } else {
    2326           4 :                 ZVAL_NULL(return_value);
    2327             :         }
    2328             : }
    2329             : /* }}} */
    2330             : 
    2331             : /* {{{ proto public Generator ReflectionGenerator::getExecutingGenerator() */
    2332           5 : ZEND_METHOD(reflection_generator, getExecutingGenerator)
    2333             : {
    2334          10 :         zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj);
    2335           5 :         zend_execute_data *ex = generator->execute_data;
    2336             :         zend_generator *current;
    2337             : 
    2338           5 :         if (zend_parse_parameters_none() == FAILURE) {
    2339           0 :                 return;
    2340             :         }
    2341             : 
    2342           5 :         REFLECTION_CHECK_VALID_GENERATOR(ex)
    2343             : 
    2344           5 :         current = zend_generator_get_current(generator);
    2345           5 :         ++GC_REFCOUNT(&current->std);
    2346             : 
    2347           5 :         ZVAL_OBJ(return_value, (zend_object *) current);
    2348             : }
    2349             : /* }}} */
    2350             : 
    2351             : 
    2352             : /* {{{ proto public static mixed ReflectionParameter::export(mixed function, mixed parameter [, bool return]) throws ReflectionException
    2353             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    2354           8 : ZEND_METHOD(reflection_parameter, export)
    2355             : {
    2356           8 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_parameter_ptr, 2);
    2357           8 : }
    2358             : /* }}} */
    2359             : 
    2360             : /* {{{ proto public void ReflectionParameter::__construct(mixed function, mixed parameter)
    2361             :    Constructor. Throws an Exception in case the given method does not exist */
    2362          31 : ZEND_METHOD(reflection_parameter, __construct)
    2363             : {
    2364             :         parameter_reference *ref;
    2365             :         zval *reference, *parameter;
    2366             :         zval *object;
    2367             :         zval name;
    2368             :         reflection_object *intern;
    2369             :         zend_function *fptr;
    2370             :         struct _zend_arg_info *arg_info;
    2371             :         int position;
    2372             :         uint32_t num_args;
    2373          31 :         zend_class_entry *ce = NULL;
    2374          31 :         zend_bool is_closure = 0;
    2375             : 
    2376          31 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &reference, &parameter) == FAILURE) {
    2377           1 :                 return;
    2378             :         }
    2379             : 
    2380          60 :         object = getThis();
    2381          30 :         intern = Z_REFLECTION_P(object);
    2382             : 
    2383             :         /* First, find the function */
    2384          60 :         switch (Z_TYPE_P(reference)) {
    2385             :                 case IS_STRING: {
    2386             :                                 size_t lcname_len;
    2387             :                                 char *lcname;
    2388             : 
    2389           6 :                                 lcname_len = Z_STRLEN_P(reference);
    2390           6 :                                 lcname = zend_str_tolower_dup(Z_STRVAL_P(reference), lcname_len);
    2391          12 :                                 if ((fptr = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len)) == NULL) {
    2392           0 :                                         efree(lcname);
    2393           0 :                                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    2394           0 :                                                 "Function %s() does not exist", Z_STRVAL_P(reference));
    2395           0 :                                         return;
    2396             :                                 }
    2397           6 :                                 efree(lcname);
    2398             :                         }
    2399           6 :                         ce = fptr->common.scope;
    2400           6 :                         break;
    2401             : 
    2402             :                 case IS_ARRAY: {
    2403             :                                 zval *classref;
    2404             :                                 zval *method;
    2405             :                                 size_t lcname_len;
    2406             :                                 char *lcname;
    2407             : 
    2408          30 :                                 if (((classref =zend_hash_index_find(Z_ARRVAL_P(reference), 0)) == NULL)
    2409          15 :                                         || ((method = zend_hash_index_find(Z_ARRVAL_P(reference), 1)) == NULL))
    2410             :                                 {
    2411           0 :                                         _DO_THROW("Expected array($object, $method) or array($classname, $method)");
    2412             :                                         /* returns out of this function */
    2413             :                                 }
    2414             : 
    2415          15 :                                 if (Z_TYPE_P(classref) == IS_OBJECT) {
    2416           8 :                                         ce = Z_OBJCE_P(classref);
    2417             :                                 } else {
    2418           7 :                                         convert_to_string_ex(classref);
    2419           7 :                                         if ((ce = zend_lookup_class(Z_STR_P(classref))) == NULL) {
    2420           1 :                                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    2421           1 :                                                                 "Class %s does not exist", Z_STRVAL_P(classref));
    2422           1 :                                                 return;
    2423             :                                         }
    2424             :                                 }
    2425             : 
    2426          14 :                                 convert_to_string_ex(method);
    2427          14 :                                 lcname_len = Z_STRLEN_P(method);
    2428          14 :                                 lcname = zend_str_tolower_dup(Z_STRVAL_P(method), lcname_len);
    2429          29 :                                 if (ce == zend_ce_closure && Z_TYPE_P(classref) == IS_OBJECT
    2430             :                                         && (lcname_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
    2431             :                                         && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
    2432          10 :                                         && (fptr = zend_get_closure_invoke_method(Z_OBJ_P(classref))) != NULL)
    2433             :                                 {
    2434             :                                         /* nothing to do. don't set is_closure since is the invoke handler,
    2435             :                                            not the closure itself */
    2436          18 :                                 } else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, lcname, lcname_len)) == NULL) {
    2437           2 :                                         efree(lcname);
    2438           4 :                                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    2439           4 :                                                 "Method %s::%s() does not exist", ZSTR_VAL(ce->name), Z_STRVAL_P(method));
    2440           2 :                                         return;
    2441             :                                 }
    2442          12 :                                 efree(lcname);
    2443             :                         }
    2444          12 :                         break;
    2445             : 
    2446             :                 case IS_OBJECT: {
    2447           7 :                                 ce = Z_OBJCE_P(reference);
    2448             : 
    2449           7 :                                 if (instanceof_function(ce, zend_ce_closure)) {
    2450           6 :                                         fptr = (zend_function *)zend_get_closure_method_def(reference);
    2451           6 :                                         Z_ADDREF_P(reference);
    2452           6 :                                         is_closure = 1;
    2453           2 :                                 } else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME))) == NULL) {
    2454           1 :                                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    2455           1 :                                                 "Method %s::%s() does not exist", ZSTR_VAL(ce->name), ZEND_INVOKE_FUNC_NAME);
    2456           1 :                                         return;
    2457             :                                 }
    2458             :                         }
    2459           6 :                         break;
    2460             : 
    2461             :                 default:
    2462           2 :                         _DO_THROW("The parameter class is expected to be either a string, an array(class, method) or a callable object");
    2463             :                         /* returns out of this function */
    2464             :         }
    2465             : 
    2466             :         /* Now, search for the parameter */
    2467          24 :         arg_info = fptr->common.arg_info;
    2468          24 :         num_args = fptr->common.num_args;
    2469          24 :         if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) {
    2470           0 :                 num_args++;
    2471             :         }
    2472          48 :         if (Z_TYPE_P(parameter) == IS_LONG) {
    2473          12 :                 position= (int)Z_LVAL_P(parameter);
    2474          12 :                 if (position < 0 || (uint32_t)position >= num_args) {
    2475           1 :                         if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
    2476           0 :                                 if (fptr->type != ZEND_OVERLOADED_FUNCTION) {
    2477           0 :                                         zend_string_release(fptr->common.function_name);
    2478             :                                 }
    2479           0 :                                 zend_free_trampoline(fptr);
    2480             :                         }
    2481           1 :                         if (is_closure) {
    2482           1 :                                 zval_ptr_dtor(reference);
    2483             :                         }
    2484           1 :                         _DO_THROW("The parameter specified by its offset could not be found");
    2485             :                         /* returns out of this function */
    2486             :                 }
    2487             :         } else {
    2488             :                 uint32_t i;
    2489             : 
    2490          12 :                 position= -1;
    2491          24 :                 convert_to_string_ex(parameter);
    2492          17 :                 if (fptr->type == ZEND_INTERNAL_FUNCTION &&
    2493           4 :                     !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
    2494           1 :                         for (i = 0; i < num_args; i++) {
    2495           1 :                                 if (arg_info[i].name) {
    2496           1 :                                         if (strcmp(((zend_internal_arg_info*)arg_info)[i].name, Z_STRVAL_P(parameter)) == 0) {
    2497           1 :                                                 position= i;
    2498           1 :                                                 break;
    2499             :                                         }
    2500             : 
    2501             :                                 }
    2502             :                         }
    2503             :                 } else {
    2504          20 :                         for (i = 0; i < num_args; i++) {
    2505          18 :                                 if (arg_info[i].name) {
    2506          18 :                                         if (strcmp(ZSTR_VAL(arg_info[i].name), Z_STRVAL_P(parameter)) == 0) {
    2507           9 :                                                 position= i;
    2508           9 :                                                 break;
    2509             :                                         }
    2510             :                                 }
    2511             :                         }
    2512             :                 }
    2513          12 :                 if (position == -1) {
    2514           2 :                         if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
    2515           0 :                                 if (fptr->type != ZEND_OVERLOADED_FUNCTION) {
    2516           0 :                                         zend_string_release(fptr->common.function_name);
    2517             :                                 }
    2518           0 :                                 zend_free_trampoline(fptr);
    2519             :                         }
    2520           2 :                         if (is_closure) {
    2521           0 :                                 zval_ptr_dtor(reference);
    2522             :                         }
    2523           2 :                         _DO_THROW("The parameter specified by its name could not be found");
    2524             :                         /* returns out of this function */
    2525             :                 }
    2526             :         }
    2527             : 
    2528          21 :         if (arg_info[position].name) {
    2529          30 :                 if (fptr->type == ZEND_INTERNAL_FUNCTION &&
    2530           7 :                     !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
    2531           4 :                         ZVAL_STRING(&name, ((zend_internal_arg_info*)arg_info)[position].name);
    2532             :                 } else {
    2533          19 :                         ZVAL_STR_COPY(&name, arg_info[position].name);
    2534             :                 }
    2535             :         } else {
    2536           0 :                 ZVAL_NULL(&name);
    2537             :         }
    2538          63 :         reflection_update_property(object, "name", &name);
    2539             : 
    2540          21 :         ref = (parameter_reference*) emalloc(sizeof(parameter_reference));
    2541          21 :         ref->arg_info = &arg_info[position];
    2542          21 :         ref->offset = (uint32_t)position;
    2543          21 :         ref->required = fptr->common.required_num_args;
    2544          21 :         ref->fptr = fptr;
    2545             :         /* TODO: copy fptr */
    2546          21 :         intern->ptr = ref;
    2547          21 :         intern->ref_type = REF_TYPE_PARAMETER;
    2548          21 :         intern->ce = ce;
    2549          21 :         if (reference && is_closure) {
    2550           5 :                 ZVAL_COPY_VALUE(&intern->obj, reference);
    2551             :         }
    2552             : }
    2553             : /* }}} */
    2554             : 
    2555             : /* {{{ proto public string ReflectionParameter::__toString()
    2556             :    Returns a string representation */
    2557           7 : ZEND_METHOD(reflection_parameter, __toString)
    2558             : {
    2559             :         reflection_object *intern;
    2560             :         parameter_reference *param;
    2561             :         string str;
    2562             : 
    2563           7 :         if (zend_parse_parameters_none() == FAILURE) {
    2564           0 :                 return;
    2565             :         }
    2566          14 :         GET_REFLECTION_OBJECT_PTR(param);
    2567           7 :         string_init(&str);
    2568           7 :         _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, "");
    2569           7 :         RETURN_NEW_STR(str.buf);
    2570             : }
    2571             : 
    2572             : /* }}} */
    2573             : 
    2574             : /* {{{ proto public string ReflectionParameter::getName()
    2575             :    Returns this parameters's name */
    2576         191 : ZEND_METHOD(reflection_parameter, getName)
    2577             : {
    2578         191 :         if (zend_parse_parameters_none() == FAILURE) {
    2579           0 :                 return;
    2580             :         }
    2581         382 :         _default_get_entry(getThis(), "name", sizeof("name")-1, return_value);
    2582             : }
    2583             : /* }}} */
    2584             : 
    2585             : /* {{{ proto public ReflectionFunction ReflectionParameter::getDeclaringFunction()
    2586             :    Returns the ReflectionFunction for the function of this parameter */
    2587           6 : ZEND_METHOD(reflection_parameter, getDeclaringFunction)
    2588             : {
    2589             :         reflection_object *intern;
    2590             :         parameter_reference *param;
    2591             : 
    2592           6 :         if (zend_parse_parameters_none() == FAILURE) {
    2593           0 :                 return;
    2594             :         }
    2595          12 :         GET_REFLECTION_OBJECT_PTR(param);
    2596             : 
    2597           6 :         if (!param->fptr->common.scope) {
    2598           8 :                 reflection_function_factory(_copy_function(param->fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, return_value);
    2599             :         } else {
    2600           4 :                 reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, return_value);
    2601             :         }
    2602             : }
    2603             : /* }}} */
    2604             : 
    2605             : /* {{{ proto public ReflectionClass|NULL ReflectionParameter::getDeclaringClass()
    2606             :    Returns in which class this parameter is defined (not the type of the parameter) */
    2607          14 : ZEND_METHOD(reflection_parameter, getDeclaringClass)
    2608             : {
    2609             :         reflection_object *intern;
    2610             :         parameter_reference *param;
    2611             : 
    2612          14 :         if (zend_parse_parameters_none() == FAILURE) {
    2613           0 :                 return;
    2614             :         }
    2615          28 :         GET_REFLECTION_OBJECT_PTR(param);
    2616             : 
    2617          14 :         if (param->fptr->common.scope) {
    2618           7 :                 zend_reflection_class_factory(param->fptr->common.scope, return_value);
    2619             :         }
    2620             : }
    2621             : /* }}} */
    2622             : 
    2623             : /* {{{ proto public ReflectionClass|NULL ReflectionParameter::getClass()
    2624             :    Returns this parameters's class hint or NULL if there is none */
    2625          20 : ZEND_METHOD(reflection_parameter, getClass)
    2626             : {
    2627             :         reflection_object *intern;
    2628             :         parameter_reference *param;
    2629             :         zend_class_entry *ce;
    2630             : 
    2631          20 :         if (zend_parse_parameters_none() == FAILURE) {
    2632           0 :                 return;
    2633             :         }
    2634          40 :         GET_REFLECTION_OBJECT_PTR(param);
    2635             : 
    2636          20 :         if (param->arg_info->class_name) {
    2637             :                 /* Class name is stored as a string, we might also get "self" or "parent"
    2638             :                  * - For "self", simply use the function scope. If scope is NULL then
    2639             :                  *   the function is global and thus self does not make any sense
    2640             :                  *
    2641             :                  * - For "parent", use the function scope's parent. If scope is NULL then
    2642             :                  *   the function is global and thus parent does not make any sense.
    2643             :                  *   If the parent is NULL then the class does not extend anything and
    2644             :                  *   thus parent does not make any sense, either.
    2645             :                  *
    2646             :                  * TODO: Think about moving these checks to the compiler or some sort of
    2647             :                  * lint-mode.
    2648             :                  */
    2649             :                 const char *class_name;
    2650             :                 size_t class_name_len;
    2651             : 
    2652          17 :                 if (param->fptr->type == ZEND_INTERNAL_FUNCTION &&
    2653           3 :                     !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
    2654           2 :                         class_name = ((zend_internal_arg_info*)param->arg_info)->class_name;
    2655           2 :                         class_name_len = strlen(class_name);
    2656             :                 } else {
    2657          10 :                         class_name = ZSTR_VAL(param->arg_info->class_name);
    2658          10 :                         class_name_len = ZSTR_LEN(param->arg_info->class_name);
    2659             :                 }
    2660          12 :                 if (0 == zend_binary_strcasecmp(class_name, class_name_len, "self", sizeof("self")- 1)) {
    2661           1 :                         ce = param->fptr->common.scope;
    2662           1 :                         if (!ce) {
    2663           0 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    2664             :                                         "Parameter uses 'self' as type hint but function is not a class member!");
    2665           0 :                                 return;
    2666             :                         }
    2667          11 :                 } else if (0 == zend_binary_strcasecmp(class_name, class_name_len, "parent", sizeof("parent")- 1)) {
    2668           0 :                         ce = param->fptr->common.scope;
    2669           0 :                         if (!ce) {
    2670           0 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    2671             :                                         "Parameter uses 'parent' as type hint but function is not a class member!");
    2672           0 :                                 return;
    2673             :                         }
    2674           0 :                         if (!ce->parent) {
    2675           0 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    2676             :                                         "Parameter uses 'parent' as type hint although class does not have a parent!");
    2677           0 :                                 return;
    2678             :                         }
    2679           0 :                         ce = ce->parent;
    2680             :                 } else {
    2681          16 :                         if (param->fptr->type == ZEND_INTERNAL_FUNCTION &&
    2682           3 :                             !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
    2683           2 :                                 zend_string *name = zend_string_init(class_name, class_name_len, 0);
    2684           2 :                                 ce = zend_lookup_class(name);
    2685             :                                 zend_string_release(name);
    2686             :                         } else {
    2687           9 :                                 ce = zend_lookup_class(param->arg_info->class_name);
    2688             :                         }
    2689          11 :                         if (!ce) {
    2690           2 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    2691             :                                         "Class %s does not exist", class_name);
    2692           2 :                                 return;
    2693             :                         }
    2694             :                 }
    2695          10 :                 zend_reflection_class_factory(ce, return_value);
    2696             :         }
    2697             : }
    2698             : /* }}} */
    2699             : 
    2700             : /* {{{ proto public bool ReflectionParameter::hasType()
    2701             :    Returns whether parameter has a type */
    2702          27 : ZEND_METHOD(reflection_parameter, hasType)
    2703             : {
    2704             :         reflection_object *intern;
    2705             :         parameter_reference *param;
    2706             : 
    2707          27 :         if (zend_parse_parameters_none() == FAILURE) {
    2708           0 :                 return;
    2709             :         }
    2710          54 :         GET_REFLECTION_OBJECT_PTR(param);
    2711             : 
    2712          27 :         RETVAL_BOOL(param->arg_info->type_hint != 0);
    2713             : }
    2714             : /* }}} */
    2715             : 
    2716             : /* {{{ proto public ReflectionType ReflectionParameter::getType()
    2717             :    Returns the type associated with the parameter */
    2718          25 : ZEND_METHOD(reflection_parameter, getType)
    2719             : {
    2720             :         reflection_object *intern;
    2721             :         parameter_reference *param;
    2722             : 
    2723          25 :         if (zend_parse_parameters_none() == FAILURE) {
    2724           0 :                 return;
    2725             :         }
    2726          50 :         GET_REFLECTION_OBJECT_PTR(param);
    2727             : 
    2728          53 :         if (((param->fptr->type == ZEND_INTERNAL_FUNCTION &&
    2729           3 :               !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ?
    2730           1 :                 ((zend_internal_arg_info*)param->arg_info)->type_hint :
    2731          24 :                 param->arg_info->type_hint) == 0)
    2732             :         {
    2733           1 :                 RETURN_NULL();
    2734             :         }
    2735          48 :         reflection_type_factory(_copy_function(param->fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, param->arg_info, return_value);
    2736             : }
    2737             : /* }}} */
    2738             : 
    2739             : /* {{{ proto public bool ReflectionParameter::isArray()
    2740             :    Returns whether parameter MUST be an array */
    2741          92 : ZEND_METHOD(reflection_parameter, isArray)
    2742             : {
    2743             :         reflection_object *intern;
    2744             :         parameter_reference *param;
    2745             : 
    2746          92 :         if (zend_parse_parameters_none() == FAILURE) {
    2747           0 :                 return;
    2748             :         }
    2749         184 :         GET_REFLECTION_OBJECT_PTR(param);
    2750             : 
    2751          92 :         RETVAL_BOOL(param->arg_info->type_hint == IS_ARRAY);
    2752             : }
    2753             : /* }}} */
    2754             : 
    2755             : /* {{{ proto public bool ReflectionParameter::isCallable()
    2756             :    Returns whether parameter MUST be callable */
    2757           3 : ZEND_METHOD(reflection_parameter, isCallable)
    2758             : {
    2759             :         reflection_object *intern;
    2760             :         parameter_reference *param;
    2761             : 
    2762           3 :         if (zend_parse_parameters_none() == FAILURE) {
    2763           0 :                 return;
    2764             :         }
    2765           6 :         GET_REFLECTION_OBJECT_PTR(param);
    2766             : 
    2767           3 :         RETVAL_BOOL(param->arg_info->type_hint == IS_CALLABLE);
    2768             : }
    2769             : /* }}} */
    2770             : 
    2771             : /* {{{ proto public bool ReflectionParameter::allowsNull()
    2772             :    Returns whether NULL is allowed as this parameters's value */
    2773          83 : ZEND_METHOD(reflection_parameter, allowsNull)
    2774             : {
    2775             :         reflection_object *intern;
    2776             :         parameter_reference *param;
    2777             : 
    2778          83 :         if (zend_parse_parameters_none() == FAILURE) {
    2779           0 :                 return;
    2780             :         }
    2781         166 :         GET_REFLECTION_OBJECT_PTR(param);
    2782             : 
    2783          83 :         RETVAL_BOOL(param->arg_info->allow_null);
    2784             : }
    2785             : /* }}} */
    2786             : 
    2787             : /* {{{ proto public bool ReflectionParameter::isPassedByReference()
    2788             :    Returns whether this parameters is passed to by reference */
    2789          96 : ZEND_METHOD(reflection_parameter, isPassedByReference)
    2790             : {
    2791             :         reflection_object *intern;
    2792             :         parameter_reference *param;
    2793             : 
    2794          96 :         if (zend_parse_parameters_none() == FAILURE) {
    2795           0 :                 return;
    2796             :         }
    2797         192 :         GET_REFLECTION_OBJECT_PTR(param);
    2798             : 
    2799          96 :         RETVAL_BOOL(param->arg_info->pass_by_reference);
    2800             : }
    2801             : /* }}} */
    2802             : 
    2803             : /* {{{ proto public bool ReflectionParameter::canBePassedByValue()
    2804             :    Returns whether this parameter can be passed by value */
    2805           8 : ZEND_METHOD(reflection_parameter, canBePassedByValue)
    2806             : {
    2807             :         reflection_object *intern;
    2808             :         parameter_reference *param;
    2809             : 
    2810           8 :         if (zend_parse_parameters_none() == FAILURE) {
    2811           0 :                 return;
    2812             :         }
    2813          16 :         GET_REFLECTION_OBJECT_PTR(param);
    2814             : 
    2815             :         /* true if it's ZEND_SEND_BY_VAL or ZEND_SEND_PREFER_REF */
    2816           8 :         RETVAL_BOOL(param->arg_info->pass_by_reference != ZEND_SEND_BY_REF);
    2817             : }
    2818             : /* }}} */
    2819             : 
    2820             : /* {{{ proto public bool ReflectionParameter::getPosition()
    2821             :    Returns whether this parameter is an optional parameter */
    2822           2 : ZEND_METHOD(reflection_parameter, getPosition)
    2823             : {
    2824             :         reflection_object *intern;
    2825             :         parameter_reference *param;
    2826             : 
    2827           2 :         if (zend_parse_parameters_none() == FAILURE) {
    2828           0 :                 return;
    2829             :         }
    2830           4 :         GET_REFLECTION_OBJECT_PTR(param);
    2831             : 
    2832           2 :         RETVAL_LONG(param->offset);
    2833             : }
    2834             : /* }}} */
    2835             : 
    2836             : /* {{{ proto public bool ReflectionParameter::isOptional()
    2837             :    Returns whether this parameter is an optional parameter */
    2838         126 : ZEND_METHOD(reflection_parameter, isOptional)
    2839             : {
    2840             :         reflection_object *intern;
    2841             :         parameter_reference *param;
    2842             : 
    2843         126 :         if (zend_parse_parameters_none() == FAILURE) {
    2844           0 :                 return;
    2845             :         }
    2846         252 :         GET_REFLECTION_OBJECT_PTR(param);
    2847             : 
    2848         126 :         RETVAL_BOOL(param->offset >= param->required);
    2849             : }
    2850             : /* }}} */
    2851             : 
    2852             : /* {{{ proto public bool ReflectionParameter::isDefaultValueAvailable()
    2853             :    Returns whether the default value of this parameter is available */
    2854         116 : ZEND_METHOD(reflection_parameter, isDefaultValueAvailable)
    2855             : {
    2856             :         reflection_object *intern;
    2857             :         parameter_reference *param;
    2858             :         zend_op *precv;
    2859             : 
    2860         116 :         if (zend_parse_parameters_none() == FAILURE) {
    2861           0 :                 return;
    2862             :         }
    2863         232 :         GET_REFLECTION_OBJECT_PTR(param);
    2864             : 
    2865         116 :         if (param->fptr->type != ZEND_USER_FUNCTION)
    2866             :         {
    2867          69 :                 RETURN_FALSE;
    2868             :         }
    2869             : 
    2870          47 :         precv = _get_recv_op((zend_op_array*)param->fptr, param->offset);
    2871          47 :         if (!precv || precv->opcode != ZEND_RECV_INIT || precv->op2_type == IS_UNUSED) {
    2872          14 :                 RETURN_FALSE;
    2873             :         }
    2874          33 :         RETURN_TRUE;
    2875             : }
    2876             : /* }}} */
    2877             : 
    2878             : /* {{{ proto public bool ReflectionParameter::getDefaultValue()
    2879             :    Returns the default value of this parameter or throws an exception */
    2880          23 : ZEND_METHOD(reflection_parameter, getDefaultValue)
    2881             : {
    2882             :         parameter_reference *param;
    2883             :         zend_op *precv;
    2884             : 
    2885          23 :         if (zend_parse_parameters_none() == FAILURE) {
    2886           0 :                 return;
    2887             :         }
    2888             : 
    2889          23 :         param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    2890          23 :         if (!param) {
    2891           0 :                 return;
    2892             :         }
    2893             : 
    2894          23 :         precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
    2895          23 :         if (!precv) {
    2896           0 :                 return;
    2897             :         }
    2898             : 
    2899          23 :         ZVAL_DUP(return_value, RT_CONSTANT(&param->fptr->op_array, precv->op2));
    2900          23 :         if (Z_CONSTANT_P(return_value)) {
    2901          10 :                 zval_update_constant_ex(return_value, param->fptr->common.scope);
    2902             :         }
    2903             : }
    2904             : /* }}} */
    2905             : 
    2906             : /* {{{ proto public bool ReflectionParameter::isDefaultValueConstant()
    2907             :    Returns whether the default value of this parameter is constant */
    2908          10 : ZEND_METHOD(reflection_parameter, isDefaultValueConstant)
    2909             : {
    2910             :         zend_op *precv;
    2911             :         parameter_reference *param;
    2912             : 
    2913          10 :         if (zend_parse_parameters_none() == FAILURE) {
    2914           0 :                 return;
    2915             :         }
    2916             : 
    2917          10 :         param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    2918          10 :         if (!param) {
    2919           0 :                 RETURN_FALSE;
    2920             :         }
    2921             : 
    2922          10 :         precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
    2923          20 :         if (precv && Z_TYPE_P(RT_CONSTANT(&param->fptr->op_array, precv->op2)) == IS_CONSTANT) {
    2924           8 :                 RETURN_TRUE;
    2925             :         }
    2926             : 
    2927           2 :         RETURN_FALSE;
    2928             : }
    2929             : /* }}} */
    2930             : 
    2931             : /* {{{ proto public mixed ReflectionParameter::getDefaultValueConstantName()
    2932             :    Returns the default value's constant name if default value is constant or null */
    2933           9 : ZEND_METHOD(reflection_parameter, getDefaultValueConstantName)
    2934             : {
    2935             :         zend_op *precv;
    2936             :         parameter_reference *param;
    2937             : 
    2938           9 :         if (zend_parse_parameters_none() == FAILURE) {
    2939           0 :                 return;
    2940             :         }
    2941             : 
    2942           9 :         param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    2943           9 :         if (!param) {
    2944           0 :                 return;
    2945             :         }
    2946             : 
    2947           9 :         precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
    2948          17 :         if (precv && Z_TYPE_P(RT_CONSTANT(&param->fptr->op_array, precv->op2)) == IS_CONSTANT) {
    2949           8 :                 RETURN_STR_COPY(Z_STR_P(RT_CONSTANT(&param->fptr->op_array, precv->op2)));
    2950             :         }
    2951             : }
    2952             : /* }}} */
    2953             : 
    2954             : /* {{{ proto public bool ReflectionParameter::isVariadic()
    2955             :    Returns whether this parameter is a variadic parameter */
    2956           4 : ZEND_METHOD(reflection_parameter, isVariadic)
    2957             : {
    2958             :         reflection_object *intern;
    2959             :         parameter_reference *param;
    2960             : 
    2961           4 :         if (zend_parse_parameters_none() == FAILURE) {
    2962           0 :                 return;
    2963             :         }
    2964           8 :         GET_REFLECTION_OBJECT_PTR(param);
    2965             : 
    2966           4 :         RETVAL_BOOL(param->arg_info->is_variadic);
    2967             : }
    2968             : /* }}} */
    2969             : 
    2970             : /* {{{ proto public bool ReflectionType::allowsNull()
    2971             :   Returns whether parameter MAY be null */
    2972          20 : ZEND_METHOD(reflection_type, allowsNull)
    2973             : {
    2974             :         reflection_object *intern;
    2975             :         type_reference *param;
    2976             : 
    2977          20 :         if (zend_parse_parameters_none() == FAILURE) {
    2978           0 :                 return;
    2979             :         }
    2980          40 :         GET_REFLECTION_OBJECT_PTR(param);
    2981             : 
    2982          20 :         RETVAL_BOOL(param->arg_info->allow_null);
    2983             : }
    2984             : /* }}} */
    2985             : 
    2986             : /* {{{ proto public bool ReflectionType::isBuiltin()
    2987             :   Returns whether parameter is a builtin type */
    2988          20 : ZEND_METHOD(reflection_type, isBuiltin)
    2989             : {
    2990             :         reflection_object *intern;
    2991             :         type_reference *param;
    2992             : 
    2993          20 :         if (zend_parse_parameters_none() == FAILURE) {
    2994           0 :                 return;
    2995             :         }
    2996          40 :         GET_REFLECTION_OBJECT_PTR(param);
    2997             : 
    2998          20 :         RETVAL_BOOL(param->arg_info->type_hint != IS_OBJECT);
    2999             : }
    3000             : /* }}} */
    3001             : 
    3002             : /* {{{ proto public string ReflectionType::__toString()
    3003             :    Return the text of the type hint */
    3004          40 : ZEND_METHOD(reflection_type, __toString)
    3005             : {
    3006             :         reflection_object *intern;
    3007             :         type_reference *param;
    3008             : 
    3009          40 :         if (zend_parse_parameters_none() == FAILURE) {
    3010           0 :                 return;
    3011             :         }
    3012          80 :         GET_REFLECTION_OBJECT_PTR(param);
    3013             : 
    3014          40 :         switch (param->arg_info->type_hint) {
    3015           4 :                 case IS_ARRAY:    RETURN_STRINGL("array", sizeof("array") - 1);
    3016           4 :                 case IS_CALLABLE: RETURN_STRINGL("callable", sizeof("callable") - 1);
    3017             :                 case IS_OBJECT:
    3018          27 :                         if (param->fptr->type == ZEND_INTERNAL_FUNCTION &&
    3019           6 :                             !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
    3020           2 :                                 RETURN_STRING(((zend_internal_arg_info*)param->arg_info)->class_name);
    3021             :                         }
    3022          20 :                         RETURN_STR_COPY(param->arg_info->class_name);
    3023           4 :                 case IS_STRING:   RETURN_STRINGL("string", sizeof("string") - 1);
    3024           4 :                 case _IS_BOOL:    RETURN_STRINGL("bool", sizeof("bool") - 1);
    3025          14 :                 case IS_LONG:     RETURN_STRINGL("int", sizeof("int") - 1);
    3026           4 :                 case IS_DOUBLE:   RETURN_STRINGL("float", sizeof("float") - 1);
    3027           2 :                 case IS_VOID:     RETURN_STRINGL("void", sizeof("void") - 1);
    3028           2 :                 case IS_ITERABLE: RETURN_STRINGL("iterable", sizeof("iterable") - 1);
    3029             :                 EMPTY_SWITCH_DEFAULT_CASE()
    3030             :         }
    3031             : }
    3032             : /* }}} */
    3033             : 
    3034             : /* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException
    3035             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    3036           8 : ZEND_METHOD(reflection_method, export)
    3037             : {
    3038           8 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_method_ptr, 2);
    3039           8 : }
    3040             : /* }}} */
    3041             : 
    3042             : /* {{{ proto public void ReflectionMethod::__construct(mixed class_or_method [, string name])
    3043             :    Constructor. Throws an Exception in case the given method does not exist */
    3044         183 : ZEND_METHOD(reflection_method, __construct)
    3045             : {
    3046             :         zval name, *classname;
    3047             :         zval *object, *orig_obj;
    3048             :         reflection_object *intern;
    3049             :         char *lcname;
    3050             :         zend_class_entry *ce;
    3051             :         zend_function *mptr;
    3052             :         char *name_str, *tmp;
    3053             :         size_t name_len, tmp_len;
    3054             :         zval ztmp;
    3055             : 
    3056         183 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
    3057          53 :                 if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
    3058           5 :                         return;
    3059             :                 }
    3060             : 
    3061          48 :                 if ((tmp = strstr(name_str, "::")) == NULL) {
    3062           5 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    3063             :                                 "Invalid method name %s", name_str);
    3064           5 :                         return;
    3065             :                 }
    3066          43 :                 classname = &ztmp;
    3067          43 :                 tmp_len = tmp - name_str;
    3068          86 :                 ZVAL_STRINGL(classname, name_str, tmp_len);
    3069          43 :                 name_len = name_len - (tmp_len + 2);
    3070          43 :                 name_str = tmp + 2;
    3071          43 :                 orig_obj = NULL;
    3072         260 :         } else if (Z_TYPE_P(classname) == IS_OBJECT) {
    3073          14 :                 orig_obj = classname;
    3074             :         } else {
    3075         116 :                 orig_obj = NULL;
    3076             :         }
    3077             : 
    3078         346 :         object = getThis();
    3079         173 :         intern = Z_REFLECTION_P(object);
    3080             : 
    3081             :         /* Find the class entry */
    3082         346 :         switch (Z_TYPE_P(classname)) {
    3083             :                 case IS_STRING:
    3084         156 :                         if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
    3085           9 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    3086           9 :                                                 "Class %s does not exist", Z_STRVAL_P(classname));
    3087           9 :                                 if (classname == &ztmp) {
    3088             :                                         zval_dtor(&ztmp);
    3089             :                                 }
    3090           9 :                                 return;
    3091             :                         }
    3092         147 :                         break;
    3093             : 
    3094             :                 case IS_OBJECT:
    3095          14 :                         ce = Z_OBJCE_P(classname);
    3096          14 :                         break;
    3097             : 
    3098             :                 default:
    3099           3 :                         if (classname == &ztmp) {
    3100             :                                 zval_dtor(&ztmp);
    3101             :                         }
    3102           3 :                         _DO_THROW("The parameter class is expected to be either a string or an object");
    3103             :                         /* returns out of this function */
    3104             :         }
    3105             : 
    3106         161 :         if (classname == &ztmp) {
    3107             :                 zval_dtor(&ztmp);
    3108             :         }
    3109             : 
    3110         161 :         lcname = zend_str_tolower_dup(name_str, name_len);
    3111             : 
    3112         177 :         if (ce == zend_ce_closure && orig_obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
    3113             :                 && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
    3114          16 :                 && (mptr = zend_get_closure_invoke_method(Z_OBJ_P(orig_obj))) != NULL)
    3115             :         {
    3116             :                 /* do nothing, mptr already set */
    3117         306 :         } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, name_len)) == NULL) {
    3118           3 :                 efree(lcname);
    3119           6 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    3120           3 :                         "Method %s::%s() does not exist", ZSTR_VAL(ce->name), name_str);
    3121           3 :                 return;
    3122             :         }
    3123         158 :         efree(lcname);
    3124             : 
    3125         158 :         ZVAL_STR_COPY(&name, mptr->common.scope->name);
    3126         474 :         reflection_update_property(object, "class", &name);
    3127         158 :         ZVAL_STR_COPY(&name, mptr->common.function_name);
    3128         474 :         reflection_update_property(object, "name", &name);
    3129         158 :         intern->ptr = mptr;
    3130         158 :         intern->ref_type = REF_TYPE_FUNCTION;
    3131         158 :         intern->ce = ce;
    3132             : }
    3133             : /* }}} */
    3134             : 
    3135             : /* {{{ proto public string ReflectionMethod::__toString()
    3136             :    Returns a string representation */
    3137          32 : ZEND_METHOD(reflection_method, __toString)
    3138             : {
    3139             :         reflection_object *intern;
    3140             :         zend_function *mptr;
    3141             :         string str;
    3142             : 
    3143          32 :         if (zend_parse_parameters_none() == FAILURE) {
    3144           0 :                 return;
    3145             :         }
    3146          64 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3147          32 :         string_init(&str);
    3148          32 :         _function_string(&str, mptr, intern->ce, "");
    3149          32 :         RETURN_NEW_STR(str.buf);
    3150             : }
    3151             : /* }}} */
    3152             : 
    3153             : /* {{{ proto public mixed ReflectionMethod::getClosure([mixed object])
    3154             :    Invokes the function */
    3155          17 : ZEND_METHOD(reflection_method, getClosure)
    3156             : {
    3157             :         reflection_object *intern;
    3158             :         zval *obj;
    3159             :         zend_function *mptr;
    3160             : 
    3161          34 :         METHOD_NOTSTATIC(reflection_method_ptr);
    3162          34 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3163             : 
    3164          17 :         if (mptr->common.fn_flags & ZEND_ACC_STATIC)  {
    3165           5 :                 zend_create_fake_closure(return_value, mptr, mptr->common.scope, mptr->common.scope, NULL);
    3166             :         } else {
    3167          12 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) {
    3168           2 :                         return;
    3169             :                 }
    3170             : 
    3171          10 :                 if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope)) {
    3172           1 :                         _DO_THROW("Given object is not an instance of the class this method was declared in");
    3173             :                         /* Returns from this function */
    3174             :                 }
    3175             : 
    3176             :                 /* This is an original closure object and __invoke is to be called. */
    3177          11 :                 if (Z_OBJCE_P(obj) == zend_ce_closure &&
    3178           1 :                         (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
    3179             :                 {
    3180           1 :                         ZVAL_COPY(return_value, obj);
    3181             :                 } else {
    3182           8 :                         zend_create_fake_closure(return_value, mptr, mptr->common.scope, Z_OBJCE_P(obj), obj);
    3183             :                 }
    3184             :         }
    3185             : }
    3186             : /* }}} */
    3187             : 
    3188             : /* {{{ proto public mixed ReflectionMethod::invoke(mixed object, mixed* args)
    3189             :    Invokes the method. */
    3190          34 : ZEND_METHOD(reflection_method, invoke)
    3191             : {
    3192             :         zval retval;
    3193          34 :         zval *params = NULL;
    3194             :         zend_object *object;
    3195             :         reflection_object *intern;
    3196             :         zend_function *mptr;
    3197          34 :         int result, num_args = 0;
    3198             :         zend_fcall_info fci;
    3199             :         zend_fcall_info_cache fcc;
    3200             :         zend_class_entry *obj_ce;
    3201             : 
    3202          68 :         METHOD_NOTSTATIC(reflection_method_ptr);
    3203             : 
    3204          68 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3205             : 
    3206          69 :         if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)
    3207          25 :                  || (mptr->common.fn_flags & ZEND_ACC_ABSTRACT))
    3208          10 :                  && intern->ignore_visibility == 0)
    3209             :         {
    3210           6 :                 if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
    3211           2 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    3212             :                                 "Trying to invoke abstract method %s::%s()",
    3213           2 :                                 ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
    3214             :                 } else {
    3215          20 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    3216             :                                 "Trying to invoke %s method %s::%s() from scope %s",
    3217           5 :                                 mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
    3218          10 :                                 ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name),
    3219          10 :                                 ZSTR_VAL(Z_OBJCE_P(getThis())->name));
    3220             :                 }
    3221           6 :                 return;
    3222             :         }
    3223             : 
    3224          28 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &params, &num_args) == FAILURE) {
    3225           1 :                 return;
    3226             :         }
    3227             : 
    3228             :         /* In case this is a static method, we should'nt pass an object_ptr
    3229             :          * (which is used as calling context aka $this). We can thus ignore the
    3230             :          * first parameter.
    3231             :          *
    3232             :          * Else, we verify that the given object is an instance of the class.
    3233             :          */
    3234          27 :         if (mptr->common.fn_flags & ZEND_ACC_STATIC) {
    3235           9 :                 object = NULL;
    3236           9 :                 obj_ce = mptr->common.scope;
    3237             :         } else {
    3238          36 :                 if (Z_TYPE(params[0]) != IS_OBJECT) {
    3239           2 :                         _DO_THROW("Non-object passed to Invoke()");
    3240             :                         /* Returns from this function */
    3241             :                 }
    3242             : 
    3243          16 :                 obj_ce = Z_OBJCE(params[0]);
    3244             : 
    3245          16 :                 if (!instanceof_function(obj_ce, mptr->common.scope)) {
    3246           2 :                         _DO_THROW("Given object is not an instance of the class this method was declared in");
    3247             :                         /* Returns from this function */
    3248             :                 }
    3249             : 
    3250          14 :                 object = Z_OBJ(params[0]);
    3251             :         }
    3252             : 
    3253          23 :         fci.size = sizeof(fci);
    3254          23 :         ZVAL_UNDEF(&fci.function_name);
    3255          23 :         fci.object = object;
    3256          23 :         fci.retval = &retval;
    3257          23 :         fci.param_count = num_args - 1;
    3258          23 :         fci.params = params + 1;
    3259          23 :         fci.no_separation = 1;
    3260             : 
    3261          23 :         fcc.initialized = 1;
    3262          23 :         fcc.function_handler = mptr;
    3263          23 :         fcc.calling_scope = obj_ce;
    3264          23 :         fcc.called_scope = intern->ce;
    3265          23 :         fcc.object = object;
    3266             : 
    3267          23 :         result = zend_call_function(&fci, &fcc);
    3268             : 
    3269          23 :         if (result == FAILURE) {
    3270           0 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    3271           0 :                         "Invocation of method %s::%s() failed", ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
    3272           0 :                 return;
    3273             :         }
    3274             : 
    3275          23 :         if (Z_TYPE(retval) != IS_UNDEF) {
    3276          20 :                 ZVAL_COPY_VALUE(return_value, &retval);
    3277             :         }
    3278             : }
    3279             : /* }}} */
    3280             : 
    3281             : /* {{{ proto public mixed ReflectionMethod::invokeArgs(mixed object, array args)
    3282             :    Invokes the function and pass its arguments as array. */
    3283          30 : ZEND_METHOD(reflection_method, invokeArgs)
    3284             : {
    3285             :         zval retval;
    3286             :         zval *params, *val, *object;
    3287             :         reflection_object *intern;
    3288             :         zend_function *mptr;
    3289             :         int i, argc;
    3290             :         int result;
    3291             :         zend_fcall_info fci;
    3292             :         zend_fcall_info_cache fcc;
    3293             :         zend_class_entry *obj_ce;
    3294             :         zval *param_array;
    3295             : 
    3296          60 :         METHOD_NOTSTATIC(reflection_method_ptr);
    3297             : 
    3298          60 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3299             : 
    3300          30 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "o!a", &object, &param_array) == FAILURE) {
    3301           7 :                 return;
    3302             :         }
    3303             : 
    3304          47 :         if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)
    3305          14 :                  || (mptr->common.fn_flags & ZEND_ACC_ABSTRACT))
    3306          10 :                  && intern->ignore_visibility == 0)
    3307             :         {
    3308           6 :                 if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
    3309           2 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    3310             :                                 "Trying to invoke abstract method %s::%s()",
    3311           2 :                                 ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
    3312             :                 } else {
    3313          20 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    3314             :                                 "Trying to invoke %s method %s::%s() from scope %s",
    3315           5 :                                 mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
    3316          10 :                                 ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name),
    3317          10 :                                 ZSTR_VAL(Z_OBJCE_P(getThis())->name));
    3318             :                 }
    3319           6 :                 return;
    3320             :         }
    3321             : 
    3322          17 :         argc = zend_hash_num_elements(Z_ARRVAL_P(param_array));
    3323             : 
    3324          17 :         params = safe_emalloc(sizeof(zval), argc, 0);
    3325          17 :         argc = 0;
    3326          45 :         ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(param_array), val) {
    3327          14 :                 ZVAL_COPY(&params[argc], val);
    3328          14 :                 argc++;
    3329             :         } ZEND_HASH_FOREACH_END();
    3330             : 
    3331             :         /* In case this is a static method, we should'nt pass an object_ptr
    3332             :          * (which is used as calling context aka $this). We can thus ignore the
    3333             :          * first parameter.
    3334             :          *
    3335             :          * Else, we verify that the given object is an instance of the class.
    3336             :          */
    3337          17 :         if (mptr->common.fn_flags & ZEND_ACC_STATIC) {
    3338           6 :                 object = NULL;
    3339           6 :                 obj_ce = mptr->common.scope;
    3340             :         } else {
    3341          11 :                 if (!object) {
    3342           0 :                         efree(params);
    3343           0 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    3344             :                                 "Trying to invoke non static method %s::%s() without an object",
    3345           0 :                                 ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
    3346           0 :                         return;
    3347             :                 }
    3348             : 
    3349          11 :                 obj_ce = Z_OBJCE_P(object);
    3350             : 
    3351          11 :                 if (!instanceof_function(obj_ce, mptr->common.scope)) {
    3352           1 :                         efree(params);
    3353           1 :                         _DO_THROW("Given object is not an instance of the class this method was declared in");
    3354             :                         /* Returns from this function */
    3355             :                 }
    3356             :         }
    3357             : 
    3358          16 :         fci.size = sizeof(fci);
    3359          16 :         ZVAL_UNDEF(&fci.function_name);
    3360          16 :         fci.object = object ? Z_OBJ_P(object) : NULL;
    3361          16 :         fci.retval = &retval;
    3362          16 :         fci.param_count = argc;
    3363          16 :         fci.params = params;
    3364          16 :         fci.no_separation = 1;
    3365             : 
    3366          16 :         fcc.initialized = 1;
    3367          16 :         fcc.function_handler = mptr;
    3368          16 :         fcc.calling_scope = obj_ce;
    3369          16 :         fcc.called_scope = intern->ce;
    3370          16 :         fcc.object = (object) ? Z_OBJ_P(object) : NULL;
    3371             : 
    3372             :         /*
    3373             :          * Copy the zend_function when calling via handler (e.g. Closure::__invoke())
    3374             :          */
    3375          16 :         if ((mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
    3376           2 :                 fcc.function_handler = _copy_function(mptr);
    3377             :         }
    3378             : 
    3379          16 :         result = zend_call_function(&fci, &fcc);
    3380             : 
    3381          30 :         for (i = 0; i < argc; i++) {
    3382          14 :                 zval_ptr_dtor(&params[i]);
    3383             :         }
    3384          16 :         efree(params);
    3385             : 
    3386          16 :         if (result == FAILURE) {
    3387           0 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    3388           0 :                         "Invocation of method %s::%s() failed", ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
    3389           0 :                 return;
    3390             :         }
    3391             : 
    3392          16 :         if (Z_TYPE(retval) != IS_UNDEF) {
    3393          13 :                 ZVAL_COPY_VALUE(return_value, &retval);
    3394             :         }
    3395             : }
    3396             : /* }}} */
    3397             : 
    3398             : /* {{{ proto public bool ReflectionMethod::isFinal()
    3399             :    Returns whether this method is final */
    3400          71 : ZEND_METHOD(reflection_method, isFinal)
    3401             : {
    3402          71 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL);
    3403          71 : }
    3404             : /* }}} */
    3405             : 
    3406             : /* {{{ proto public bool ReflectionMethod::isAbstract()
    3407             :    Returns whether this method is abstract */
    3408          72 : ZEND_METHOD(reflection_method, isAbstract)
    3409             : {
    3410          72 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_ABSTRACT);
    3411          72 : }
    3412             : /* }}} */
    3413             : 
    3414             : /* {{{ proto public bool ReflectionMethod::isPublic()
    3415             :    Returns whether this method is public */
    3416          71 : ZEND_METHOD(reflection_method, isPublic)
    3417             : {
    3418          71 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC);
    3419          71 : }
    3420             : /* }}} */
    3421             : 
    3422             : /* {{{ proto public bool ReflectionMethod::isPrivate()
    3423             :    Returns whether this method is private */
    3424          71 : ZEND_METHOD(reflection_method, isPrivate)
    3425             : {
    3426          71 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PRIVATE);
    3427          71 : }
    3428             : /* }}} */
    3429             : 
    3430             : /* {{{ proto public bool ReflectionMethod::isProtected()
    3431             :    Returns whether this method is protected */
    3432          71 : ZEND_METHOD(reflection_method, isProtected)
    3433             : {
    3434          71 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROTECTED);
    3435          71 : }
    3436             : /* }}} */
    3437             : 
    3438             : /* {{{ proto public bool ReflectionMethod::isStatic()
    3439             :    Returns whether this method is static */
    3440          71 : ZEND_METHOD(reflection_method, isStatic)
    3441             : {
    3442          71 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_STATIC);
    3443          71 : }
    3444             : /* }}} */
    3445             : 
    3446             : /* {{{ proto public bool ReflectionFunction::isDeprecated()
    3447             :    Returns whether this function is deprecated */
    3448           1 : ZEND_METHOD(reflection_function, isDeprecated)
    3449             : {
    3450           1 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_DEPRECATED);
    3451           1 : }
    3452             : /* }}} */
    3453             : 
    3454             : /* {{{ proto public bool ReflectionFunction::isGenerator()
    3455             :    Returns whether this function is a generator */
    3456           6 : ZEND_METHOD(reflection_function, isGenerator)
    3457             : {
    3458           6 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_GENERATOR);
    3459           6 : }
    3460             : /* }}} */
    3461             : 
    3462             : /* {{{ proto public bool ReflectionFunction::isVariadic()
    3463             :    Returns whether this function is variadic */
    3464           3 : ZEND_METHOD(reflection_function, isVariadic)
    3465             : {
    3466           3 :         _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_VARIADIC);
    3467           3 : }
    3468             : /* }}} */
    3469             : 
    3470             : /* {{{ proto public bool ReflectionFunction::inNamespace()
    3471             :    Returns whether this function is defined in namespace */
    3472           2 : ZEND_METHOD(reflection_function, inNamespace)
    3473             : {
    3474             :         zval *name;
    3475             :         const char *backslash;
    3476             : 
    3477           2 :         if (zend_parse_parameters_none() == FAILURE) {
    3478           0 :                 return;
    3479             :         }
    3480           4 :         if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) {
    3481           0 :                 RETURN_FALSE;
    3482             :         }
    3483           5 :         if (Z_TYPE_P(name) == IS_STRING
    3484           2 :                 && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name)))
    3485           1 :                 && backslash > Z_STRVAL_P(name))
    3486             :         {
    3487           1 :                 RETURN_TRUE;
    3488             :         }
    3489           1 :         RETURN_FALSE;
    3490             : }
    3491             : /* }}} */
    3492             : 
    3493             : /* {{{ proto public string ReflectionFunction::getNamespaceName()
    3494             :    Returns the name of namespace where this function is defined */
    3495           2 : ZEND_METHOD(reflection_function, getNamespaceName)
    3496             : {
    3497             :         zval *name;
    3498             :         const char *backslash;
    3499             : 
    3500           2 :         if (zend_parse_parameters_none() == FAILURE) {
    3501           0 :                 return;
    3502             :         }
    3503           4 :         if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) {
    3504           0 :                 RETURN_FALSE;
    3505             :         }
    3506           5 :         if (Z_TYPE_P(name) == IS_STRING
    3507           2 :                 && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name)))
    3508           1 :                 && backslash > Z_STRVAL_P(name))
    3509             :         {
    3510           2 :                 RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name));
    3511             :         }
    3512           1 :         RETURN_EMPTY_STRING();
    3513             : }
    3514             : /* }}} */
    3515             : 
    3516             : /* {{{ proto public string ReflectionFunction::getShortName()
    3517             :    Returns the short name of the function (without namespace part) */
    3518           3 : ZEND_METHOD(reflection_function, getShortName)
    3519             : {
    3520             :         zval *name;
    3521             :         const char *backslash;
    3522             : 
    3523           3 :         if (zend_parse_parameters_none() == FAILURE) {
    3524           0 :                 return;
    3525             :         }
    3526           6 :         if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) {
    3527           0 :                 RETURN_FALSE;
    3528             :         }
    3529           7 :         if (Z_TYPE_P(name) == IS_STRING
    3530           3 :                 && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name)))
    3531           1 :                 && backslash > Z_STRVAL_P(name))
    3532             :         {
    3533           2 :                 RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1));
    3534             :         }
    3535           2 :         ZVAL_DEREF(name);
    3536           2 :         ZVAL_COPY(return_value, name);
    3537             : }
    3538             : /* }}} */
    3539             : 
    3540             : /* {{{ proto public bool ReflectionFunctionAbstract:hasReturnType()
    3541             :    Return whether the function has a return type */
    3542           7 : ZEND_METHOD(reflection_function, hasReturnType)
    3543             : {
    3544             :         reflection_object *intern;
    3545             :         zend_function *fptr;
    3546             : 
    3547           7 :         if (zend_parse_parameters_none() == FAILURE) {
    3548           0 :                 return;
    3549             :         }
    3550             : 
    3551          14 :         GET_REFLECTION_OBJECT_PTR(fptr);
    3552             : 
    3553           7 :         RETVAL_BOOL(fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE);
    3554             : }
    3555             : /* }}} */
    3556             : 
    3557             : /* {{{ proto public string ReflectionFunctionAbstract::getReturnType()
    3558             :    Returns the return type associated with the function */
    3559          17 : ZEND_METHOD(reflection_function, getReturnType)
    3560             : {
    3561             :         reflection_object *intern;
    3562             :         zend_function *fptr;
    3563             : 
    3564          17 :         if (zend_parse_parameters_none() == FAILURE) {
    3565           0 :                 return;
    3566             :         }
    3567             : 
    3568          34 :         GET_REFLECTION_OBJECT_PTR(fptr);
    3569             : 
    3570          17 :         if (!(fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) {
    3571           1 :                 RETURN_NULL();
    3572             :         }
    3573             : 
    3574          32 :         reflection_type_factory(_copy_function(fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, &fptr->common.arg_info[-1], return_value);
    3575             : }
    3576             : /* }}} */
    3577             : 
    3578             : /* {{{ proto public bool ReflectionMethod::isConstructor()
    3579             :    Returns whether this method is the constructor */
    3580          90 : ZEND_METHOD(reflection_method, isConstructor)
    3581             : {
    3582             :         reflection_object *intern;
    3583             :         zend_function *mptr;
    3584             : 
    3585          90 :         if (zend_parse_parameters_none() == FAILURE) {
    3586           1 :                 return;
    3587             :         }
    3588         178 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3589             :         /* we need to check if the ctor is the ctor of the class level we we
    3590             :          * looking at since we might be looking at an inherited old style ctor
    3591             :          * defined in base class. */
    3592          89 :         RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_CTOR && intern->ce->constructor && intern->ce->constructor->common.scope == mptr->common.scope);
    3593             : }
    3594             : /* }}} */
    3595             : 
    3596             : /* {{{ proto public bool ReflectionMethod::isDestructor()
    3597             :    Returns whether this method is static */
    3598          71 : ZEND_METHOD(reflection_method, isDestructor)
    3599             : {
    3600             :         reflection_object *intern;
    3601             :         zend_function *mptr;
    3602             : 
    3603          71 :         if (zend_parse_parameters_none() == FAILURE) {
    3604           1 :                 return;
    3605             :         }
    3606         140 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3607          70 :         RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_DTOR);
    3608             : }
    3609             : /* }}} */
    3610             : 
    3611             : /* {{{ proto public int ReflectionMethod::getModifiers()
    3612             :    Returns a bitfield of the access modifiers for this method */
    3613         114 : ZEND_METHOD(reflection_method, getModifiers)
    3614             : {
    3615             :         reflection_object *intern;
    3616             :         zend_function *mptr;
    3617             : 
    3618         114 :         if (zend_parse_parameters_none() == FAILURE) {
    3619           2 :                 return;
    3620             :         }
    3621         224 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3622             : 
    3623         112 :         RETURN_LONG(mptr->common.fn_flags);
    3624             : }
    3625             : /* }}} */
    3626             : 
    3627             : /* {{{ proto public ReflectionClass ReflectionMethod::getDeclaringClass()
    3628             :    Get the declaring class */
    3629          14 : ZEND_METHOD(reflection_method, getDeclaringClass)
    3630             : {
    3631             :         reflection_object *intern;
    3632             :         zend_function *mptr;
    3633             : 
    3634          28 :         METHOD_NOTSTATIC(reflection_method_ptr);
    3635          28 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3636             : 
    3637          14 :         if (zend_parse_parameters_none() == FAILURE) {
    3638           0 :                 return;
    3639             :         }
    3640             : 
    3641          14 :         zend_reflection_class_factory(mptr->common.scope, return_value);
    3642             : }
    3643             : /* }}} */
    3644             : 
    3645             : /* {{{ proto public ReflectionClass ReflectionMethod::getPrototype()
    3646             :    Get the prototype */
    3647           1 : ZEND_METHOD(reflection_method, getPrototype)
    3648             : {
    3649             :         reflection_object *intern;
    3650             :         zend_function *mptr;
    3651             : 
    3652           2 :         METHOD_NOTSTATIC(reflection_method_ptr);
    3653           2 :         GET_REFLECTION_OBJECT_PTR(mptr);
    3654             : 
    3655           1 :         if (zend_parse_parameters_none() == FAILURE) {
    3656           0 :                 return;
    3657             :         }
    3658             : 
    3659           1 :         if (!mptr->common.prototype) {
    3660           0 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    3661           0 :                         "Method %s::%s does not have a prototype", ZSTR_VAL(intern->ce->name), ZSTR_VAL(mptr->common.function_name));
    3662           0 :                 return;
    3663             :         }
    3664             : 
    3665           1 :         reflection_method_factory(mptr->common.prototype->common.scope, mptr->common.prototype, NULL, return_value);
    3666             : }
    3667             : /* }}} */
    3668             : 
    3669             : /* {{{ proto public void ReflectionMethod::setAccessible(bool visible)
    3670             :    Sets whether non-public methods can be invoked */
    3671           4 : ZEND_METHOD(reflection_method, setAccessible)
    3672             : {
    3673             :         reflection_object *intern;
    3674             :         zend_bool visible;
    3675             : 
    3676           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &visible) == FAILURE) {
    3677           0 :                 return;
    3678             :         }
    3679             : 
    3680           8 :         intern = Z_REFLECTION_P(getThis());
    3681             : 
    3682           4 :         intern->ignore_visibility = visible;
    3683             : }
    3684             : /* }}} */
    3685             : 
    3686             : /* {{{ proto public void ReflectionClassConstant::__construct(mixed class, string name)
    3687             :    Constructor. Throws an Exception in case the given class constant does not exist */
    3688          15 : ZEND_METHOD(reflection_class_constant, __construct)
    3689             : {
    3690             :         zval *classname, *object, name, cname;
    3691             :         zend_string *constname;
    3692             :         reflection_object *intern;
    3693             :         zend_class_entry *ce;
    3694          15 :         zend_class_constant *constant = NULL;
    3695             : 
    3696          15 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zS", &classname, &constname) == FAILURE) {
    3697           0 :                 return;
    3698             :         }
    3699             : 
    3700          30 :         object = getThis();
    3701          15 :         intern = Z_REFLECTION_P(object);
    3702             : 
    3703             :         /* Find the class entry */
    3704          30 :         switch (Z_TYPE_P(classname)) {
    3705             :                 case IS_STRING:
    3706          11 :                         if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
    3707           0 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    3708           0 :                                                 "Class %s does not exist", Z_STRVAL_P(classname));
    3709           0 :                                 return;
    3710             :                         }
    3711          11 :                         break;
    3712             : 
    3713             :                 case IS_OBJECT:
    3714           4 :                         ce = Z_OBJCE_P(classname);
    3715           4 :                         break;
    3716             : 
    3717             :                 default:
    3718           0 :                         _DO_THROW("The parameter class is expected to be either a string or an object");
    3719             :                         /* returns out of this function */
    3720             :         }
    3721             : 
    3722          30 :         if ((constant = zend_hash_find_ptr(&ce->constants_table, constname)) == NULL) {
    3723           1 :                 zend_throw_exception_ex(reflection_exception_ptr, 0, "Class Constant %s::%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(constname));
    3724           1 :                 return;
    3725             :         }
    3726             : 
    3727          14 :         ZVAL_STR_COPY(&name, constname);
    3728          14 :         ZVAL_STR_COPY(&cname, ce->name);
    3729             : 
    3730          14 :         intern->ptr = constant;
    3731          14 :         intern->ref_type = REF_TYPE_CLASS_CONSTANT;
    3732          14 :         intern->ce = constant->ce;
    3733          14 :         intern->ignore_visibility = 0;
    3734          42 :         reflection_update_property(object, "name", &name);
    3735          42 :         reflection_update_property(object, "class", &cname);
    3736             : }
    3737             : /* }}} */
    3738             : 
    3739             : /* {{{ proto public string ReflectionClassConstant::__toString()
    3740             :    Returns a string representation */
    3741          13 : ZEND_METHOD(reflection_class_constant, __toString)
    3742             : {
    3743             :         reflection_object *intern;
    3744             :         zend_class_constant *ref;
    3745             :         string str;
    3746             :         zval name;
    3747             : 
    3748          13 :         if (zend_parse_parameters_none() == FAILURE) {
    3749           0 :                 return;
    3750             :         }
    3751          26 :         GET_REFLECTION_OBJECT_PTR(ref);
    3752          13 :         string_init(&str);
    3753          26 :         _default_get_entry(getThis(), "name", sizeof("name")-1, &name);
    3754          13 :         _class_const_string(&str, Z_STRVAL(name), ref, "");
    3755          13 :         zval_ptr_dtor(&name);
    3756          13 :         RETURN_NEW_STR(str.buf);
    3757             : }
    3758             : /* }}} */
    3759             : 
    3760             : /* {{{ proto public string ReflectionClassConstant::getName()
    3761             :    Returns the constant' name */
    3762          10 : ZEND_METHOD(reflection_class_constant, getName)
    3763             : {
    3764          10 :         if (zend_parse_parameters_none() == FAILURE) {
    3765           0 :                 return;
    3766             :         }
    3767          20 :         _default_get_entry(getThis(), "name", sizeof("name")-1, return_value);
    3768             : }
    3769             : /* }}} */
    3770             : 
    3771          12 : static void _class_constant_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /* {{{ */
    3772             : {
    3773             :         reflection_object *intern;
    3774             :         zend_class_constant *ref;
    3775             : 
    3776          12 :         if (zend_parse_parameters_none() == FAILURE) {
    3777           0 :                 return;
    3778             :         }
    3779          24 :         GET_REFLECTION_OBJECT_PTR(ref);
    3780          12 :         RETURN_BOOL(Z_ACCESS_FLAGS(ref->value) & mask);
    3781             : }
    3782             : /* }}} */
    3783             : 
    3784             : /* {{{ proto public bool ReflectionClassConstant::isPublic()
    3785             :    Returns whether this constant is public */
    3786           4 : ZEND_METHOD(reflection_class_constant, isPublic)
    3787             : {
    3788           4 :         _class_constant_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC);
    3789           4 : }
    3790             : /* }}} */
    3791             : 
    3792             : /* {{{ proto public bool ReflectionClassConstant::isPrivate()
    3793             :    Returns whether this constant is private */
    3794           4 : ZEND_METHOD(reflection_class_constant, isPrivate)
    3795             : {
    3796           4 :         _class_constant_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PRIVATE);
    3797           4 : }
    3798             : /* }}} */
    3799             : 
    3800             : /* {{{ proto public bool ReflectionClassConstant::isProtected()
    3801             :    Returns whether this constant is protected */
    3802           4 : ZEND_METHOD(reflection_class_constant, isProtected)
    3803             : {
    3804           4 :         _class_constant_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROTECTED);
    3805           4 : }
    3806             : /* }}} */
    3807             : 
    3808             : /* {{{ proto public int ReflectionClassConstant::getModifiers()
    3809             :    Returns a bitfield of the access modifiers for this constant */
    3810           4 : ZEND_METHOD(reflection_class_constant, getModifiers)
    3811             : {
    3812             :         reflection_object *intern;
    3813             :         zend_class_constant *ref;
    3814             : 
    3815           4 :         if (zend_parse_parameters_none() == FAILURE) {
    3816           0 :                 return;
    3817             :         }
    3818           8 :         GET_REFLECTION_OBJECT_PTR(ref);
    3819             : 
    3820           4 :         RETURN_LONG(Z_ACCESS_FLAGS(ref->value));
    3821             : }
    3822             : /* }}} */
    3823             : 
    3824             : /* {{{ proto public mixed ReflectionClassConstant::getValue()
    3825             :    Returns this constant's value */
    3826           5 : ZEND_METHOD(reflection_class_constant, getValue)
    3827             : {
    3828             :         reflection_object *intern;
    3829             :         zend_class_constant *ref;
    3830             : 
    3831           5 :         if (zend_parse_parameters_none() == FAILURE) {
    3832           0 :                 return;
    3833             :         }
    3834          10 :         GET_REFLECTION_OBJECT_PTR(ref);
    3835             : 
    3836           5 :         ZVAL_DUP(return_value, &ref->value);
    3837           5 :         if (Z_CONSTANT_P(return_value)) {
    3838           1 :                 zval_update_constant_ex(return_value, ref->ce);
    3839             :         }
    3840             : }
    3841             : /* }}} */
    3842             : 
    3843             : /* {{{ proto public ReflectionClass ReflectionClassConstant::getDeclaringClass()
    3844             :    Get the declaring class */
    3845           4 : ZEND_METHOD(reflection_class_constant, getDeclaringClass)
    3846             : {
    3847             :         reflection_object *intern;
    3848             :         zend_class_constant *ref;
    3849             : 
    3850           4 :         if (zend_parse_parameters_none() == FAILURE) {
    3851           0 :                 return;
    3852             :         }
    3853           8 :         GET_REFLECTION_OBJECT_PTR(ref);
    3854             : 
    3855           4 :         zend_reflection_class_factory(ref->ce, return_value);
    3856             : }
    3857             : /* }}} */
    3858             : 
    3859             : /* {{{ proto public string ReflectionClassConstant::getDocComment()
    3860             :    Returns the doc comment for this constant */
    3861          10 : ZEND_METHOD(reflection_class_constant, getDocComment)
    3862             : {
    3863             :         reflection_object *intern;
    3864             :         zend_class_constant *ref;
    3865             : 
    3866          10 :         if (zend_parse_parameters_none() == FAILURE) {
    3867           0 :                 return;
    3868             :         }
    3869          20 :         GET_REFLECTION_OBJECT_PTR(ref);
    3870          10 :         if (ref->doc_comment) {
    3871           6 :                 RETURN_STR_COPY(ref->doc_comment);
    3872             :         }
    3873           4 :         RETURN_FALSE;
    3874             : }
    3875             : /* }}} */
    3876             : 
    3877             : /* {{{ proto public static mixed ReflectionClass::export(mixed argument [, bool return]) throws ReflectionException
    3878             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    3879          11 : ZEND_METHOD(reflection_class, export)
    3880             : {
    3881          11 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_class_ptr, 1);
    3882          11 : }
    3883             : /* }}} */
    3884             : 
    3885             : /* {{{ reflection_class_object_ctor */
    3886         547 : static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_object)
    3887             : {
    3888             :         zval *argument;
    3889             :         zval *object;
    3890             :         zval classname;
    3891             :         reflection_object *intern;
    3892             :         zend_class_entry *ce;
    3893             : 
    3894         547 :         if (is_object) {
    3895         105 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &argument) == FAILURE) {
    3896           7 :                         return;
    3897             :                 }
    3898             :         } else {
    3899         442 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &argument) == FAILURE) {
    3900           2 :                         return;
    3901             :                 }
    3902             :         }
    3903             : 
    3904        1076 :         object = getThis();
    3905         538 :         intern = Z_REFLECTION_P(object);
    3906             : 
    3907        1076 :         if (Z_TYPE_P(argument) == IS_OBJECT) {
    3908         121 :                 ZVAL_STR_COPY(&classname, Z_OBJCE_P(argument)->name);
    3909         363 :                 reflection_update_property(object, "name", &classname);
    3910         121 :                 intern->ptr = Z_OBJCE_P(argument);
    3911         121 :                 if (is_object) {
    3912          98 :                         ZVAL_COPY_VALUE(&intern->obj, argument);
    3913          98 :                         zval_add_ref(argument);
    3914             :                 }
    3915             :         } else {
    3916         838 :                 convert_to_string_ex(argument);
    3917         417 :                 if ((ce = zend_lookup_class(Z_STR_P(argument))) == NULL) {
    3918           8 :                         if (!EG(exception)) {
    3919           8 :                                 zend_throw_exception_ex(reflection_exception_ptr, -1, "Class %s does not exist", Z_STRVAL_P(argument));
    3920             :                         }
    3921           8 :                         return;
    3922             :                 }
    3923             : 
    3924         409 :                 ZVAL_STR_COPY(&classname, ce->name);
    3925        1227 :                 reflection_update_property(object, "name", &classname);
    3926             : 
    3927         409 :                 intern->ptr = ce;
    3928             :         }
    3929         530 :         intern->ref_type = REF_TYPE_OTHER;
    3930             : }
    3931             : /* }}} */
    3932             : 
    3933             : /* {{{ proto public void ReflectionClass::__construct(mixed argument) throws ReflectionException
    3934             :    Constructor. Takes a string or an instance as an argument */
    3935         442 : ZEND_METHOD(reflection_class, __construct)
    3936             : {
    3937         442 :         reflection_class_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    3938         442 : }
    3939             : /* }}} */
    3940             : 
    3941             : /* {{{ add_class_vars */
    3942          37 : static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value)
    3943             : {
    3944             :         zend_property_info *prop_info;
    3945             :         zval *prop, prop_copy;
    3946             :         zend_string *key;
    3947             : 
    3948         623 :         ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
    3949         958 :                 if (((prop_info->flags & ZEND_ACC_SHADOW) &&
    3950          24 :                      prop_info->ce != ce) ||
    3951         269 :                     ((prop_info->flags & ZEND_ACC_PROTECTED) &&
    3952          63 :                      !zend_check_protected(prop_info->ce, ce)) ||
    3953         269 :                     ((prop_info->flags & ZEND_ACC_PRIVATE) &&
    3954          40 :                      prop_info->ce != ce)) {
    3955          24 :                         continue;
    3956             :                 }
    3957         269 :                 prop = NULL;
    3958         326 :                 if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) {
    3959          57 :                         prop = &ce->default_static_members_table[prop_info->offset];
    3960         212 :                 } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
    3961          65 :                         prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
    3962             :                 }
    3963         269 :                 if (!prop) {
    3964         147 :                         continue;
    3965             :                 }
    3966             : 
    3967             :                 /* copy: enforce read only access */
    3968         122 :                 ZVAL_DEREF(prop);
    3969         122 :                 ZVAL_DUP(&prop_copy, prop);
    3970             : 
    3971             :                 /* this is necessary to make it able to work with default array
    3972             :                 * properties, returned to user */
    3973         122 :                 if (Z_CONSTANT(prop_copy)) {
    3974           0 :                         if (UNEXPECTED(zval_update_constant_ex(&prop_copy, NULL) != SUCCESS)) {
    3975           0 :                                 return;
    3976             :                         }
    3977             :                 }
    3978             : 
    3979         122 :                 zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy);
    3980             :         } ZEND_HASH_FOREACH_END();
    3981             : }
    3982             : /* }}} */
    3983             : 
    3984             : /* {{{ proto public array ReflectionClass::getStaticProperties()
    3985             :    Returns an associative array containing all static property values of the class */
    3986          17 : ZEND_METHOD(reflection_class, getStaticProperties)
    3987             : {
    3988             :         reflection_object *intern;
    3989             :         zend_class_entry *ce;
    3990             : 
    3991          17 :         if (zend_parse_parameters_none() == FAILURE) {
    3992           4 :                 return;
    3993             :         }
    3994             : 
    3995          26 :         GET_REFLECTION_OBJECT_PTR(ce);
    3996             : 
    3997          13 :         if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
    3998           0 :                 return;
    3999             :         }
    4000             : 
    4001          13 :         array_init(return_value);
    4002          13 :         add_class_vars(ce, 1, return_value);
    4003             : }
    4004             : /* }}} */
    4005             : 
    4006             : /* {{{ proto public mixed ReflectionClass::getStaticPropertyValue(string name [, mixed default])
    4007             :    Returns the value of a static property */
    4008          22 : ZEND_METHOD(reflection_class, getStaticPropertyValue)
    4009             : {
    4010             :         reflection_object *intern;
    4011             :         zend_class_entry *ce;
    4012             :         zend_string *name;
    4013          22 :         zval *prop, *def_value = NULL;
    4014             : 
    4015          22 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|z", &name, &def_value) == FAILURE) {
    4016           3 :                 return;
    4017             :         }
    4018             : 
    4019          38 :         GET_REFLECTION_OBJECT_PTR(ce);
    4020             : 
    4021          19 :         if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
    4022           0 :                 return;
    4023             :         }
    4024          19 :         prop = zend_std_get_static_property(ce, name, 1);
    4025          19 :         if (!prop) {
    4026          10 :                 if (def_value) {
    4027           2 :                         ZVAL_COPY(return_value, def_value);
    4028             :                 } else {
    4029          16 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    4030          16 :                                 "Class %s does not have a property named %s", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    4031             :                 }
    4032          10 :                 return;
    4033             :         } else {
    4034           9 :                 ZVAL_DEREF(prop);
    4035           9 :                 ZVAL_COPY(return_value, prop);
    4036             :         }
    4037             : }
    4038             : /* }}} */
    4039             : 
    4040             : /* {{{ proto public void ReflectionClass::setStaticPropertyValue(string $name, mixed $value)
    4041             :    Sets the value of a static property */
    4042          11 : ZEND_METHOD(reflection_class, setStaticPropertyValue)
    4043             : {
    4044             :         reflection_object *intern;
    4045             :         zend_class_entry *ce;
    4046             :         zend_string *name;
    4047             :         zval *variable_ptr, *value;
    4048             : 
    4049          11 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &name, &value) == FAILURE) {
    4050           4 :                 return;
    4051             :         }
    4052             : 
    4053          14 :         GET_REFLECTION_OBJECT_PTR(ce);
    4054             : 
    4055           7 :         if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
    4056           0 :                 return;
    4057             :         }
    4058           7 :         variable_ptr = zend_std_get_static_property(ce, name, 1);
    4059           7 :         if (!variable_ptr) {
    4060           6 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    4061           6 :                                 "Class %s does not have a property named %s", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    4062           3 :                 return;
    4063             :         }
    4064           4 :         ZVAL_DEREF(variable_ptr);
    4065           4 :         zval_ptr_dtor(variable_ptr);
    4066           4 :         ZVAL_COPY(variable_ptr, value);
    4067             : }
    4068             : /* }}} */
    4069             : 
    4070             : /* {{{ proto public array ReflectionClass::getDefaultProperties()
    4071             :    Returns an associative array containing copies of all default property values of the class */
    4072          16 : ZEND_METHOD(reflection_class, getDefaultProperties)
    4073             : {
    4074             :         reflection_object *intern;
    4075             :         zend_class_entry *ce;
    4076             : 
    4077          16 :         if (zend_parse_parameters_none() == FAILURE) {
    4078           4 :                 return;
    4079             :         }
    4080          24 :         GET_REFLECTION_OBJECT_PTR(ce);
    4081          12 :         array_init(return_value);
    4082          12 :         if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
    4083           0 :                 return;
    4084             :         }
    4085          12 :         add_class_vars(ce, 1, return_value);
    4086          12 :         add_class_vars(ce, 0, return_value);
    4087             : }
    4088             : /* }}} */
    4089             : 
    4090             : /* {{{ proto public string ReflectionClass::__toString()
    4091             :    Returns a string representation */
    4092          39 : ZEND_METHOD(reflection_class, __toString)
    4093             : {
    4094             :         reflection_object *intern;
    4095             :         zend_class_entry *ce;
    4096             :         string str;
    4097             : 
    4098          39 :         if (zend_parse_parameters_none() == FAILURE) {
    4099           0 :                 return;
    4100             :         }
    4101          78 :         GET_REFLECTION_OBJECT_PTR(ce);
    4102          39 :         string_init(&str);
    4103          39 :         _class_string(&str, ce, &intern->obj, "");
    4104          39 :         RETURN_NEW_STR(str.buf);
    4105             : }
    4106             : /* }}} */
    4107             : 
    4108             : /* {{{ proto public string ReflectionClass::getName()
    4109             :    Returns the class' name */
    4110          74 : ZEND_METHOD(reflection_class, getName)
    4111             : {
    4112          74 :         if (zend_parse_parameters_none() == FAILURE) {
    4113           5 :                 return;
    4114             :         }
    4115         138 :         _default_get_entry(getThis(), "name", sizeof("name")-1, return_value);
    4116             : }
    4117             : /* }}} */
    4118             : 
    4119             : /* {{{ proto public bool ReflectionClass::isInternal()
    4120             :    Returns whether this class is an internal class */
    4121          18 : ZEND_METHOD(reflection_class, isInternal)
    4122             : {
    4123             :         reflection_object *intern;
    4124             :         zend_class_entry *ce;
    4125             : 
    4126          18 :         if (zend_parse_parameters_none() == FAILURE) {
    4127           4 :                 return;
    4128             :         }
    4129          28 :         GET_REFLECTION_OBJECT_PTR(ce);
    4130          14 :         RETURN_BOOL(ce->type == ZEND_INTERNAL_CLASS);
    4131             : }
    4132             : /* }}} */
    4133             : 
    4134             : /* {{{ proto public bool ReflectionClass::isUserDefined()
    4135             :    Returns whether this class is user-defined */
    4136          18 : ZEND_METHOD(reflection_class, isUserDefined)
    4137             : {
    4138             :         reflection_object *intern;
    4139             :         zend_class_entry *ce;
    4140             : 
    4141          18 :         if (zend_parse_parameters_none() == FAILURE) {
    4142           4 :                 return;
    4143             :         }
    4144          28 :         GET_REFLECTION_OBJECT_PTR(ce);
    4145          14 :         RETURN_BOOL(ce->type == ZEND_USER_CLASS);
    4146             : }
    4147             : /* }}} */
    4148             : 
    4149             : /* {{{ proto public bool ReflectionClass::isAnonymous()
    4150             :    Returns whether this class is anonymous */
    4151           2 : ZEND_METHOD(reflection_class, isAnonymous)
    4152             : {
    4153             :         reflection_object *intern;
    4154             :         zend_class_entry *ce;
    4155             : 
    4156           2 :         if (zend_parse_parameters_none() == FAILURE) {
    4157           0 :                 return;
    4158             :         }
    4159           4 :         GET_REFLECTION_OBJECT_PTR(ce);
    4160           2 :         RETURN_BOOL(ce->ce_flags & ZEND_ACC_ANON_CLASS);
    4161             : }
    4162             : /* }}} */
    4163             : 
    4164             : /* {{{ proto public string ReflectionClass::getFileName()
    4165             :    Returns the filename of the file this class was declared in */
    4166          10 : ZEND_METHOD(reflection_class, getFileName)
    4167             : {
    4168             :         reflection_object *intern;
    4169             :         zend_class_entry *ce;
    4170             : 
    4171          10 :         if (zend_parse_parameters_none() == FAILURE) {
    4172           4 :                 return;
    4173             :         }
    4174          12 :         GET_REFLECTION_OBJECT_PTR(ce);
    4175           6 :         if (ce->type == ZEND_USER_CLASS) {
    4176           4 :                 RETURN_STR_COPY(ce->info.user.filename);
    4177             :         }
    4178           2 :         RETURN_FALSE;
    4179             : }
    4180             : /* }}} */
    4181             : 
    4182             : /* {{{ proto public int ReflectionClass::getStartLine()
    4183             :    Returns the line this class' declaration starts at */
    4184          12 : ZEND_METHOD(reflection_class, getStartLine)
    4185             : {
    4186             :         reflection_object *intern;
    4187             :         zend_class_entry *ce;
    4188             : 
    4189          12 :         if (zend_parse_parameters_none() == FAILURE) {
    4190           4 :                 return;
    4191             :         }
    4192          16 :         GET_REFLECTION_OBJECT_PTR(ce);
    4193           8 :         if (ce->type == ZEND_USER_FUNCTION) {
    4194           6 :                 RETURN_LONG(ce->info.user.line_start);
    4195             :         }
    4196           2 :         RETURN_FALSE;
    4197             : }
    4198             : /* }}} */
    4199             : 
    4200             : /* {{{ proto public int ReflectionClass::getEndLine()
    4201             :    Returns the line this class' declaration ends at */
    4202          10 : ZEND_METHOD(reflection_class, getEndLine)
    4203             : {
    4204             :         reflection_object *intern;
    4205             :         zend_class_entry *ce;
    4206             : 
    4207          10 :         if (zend_parse_parameters_none() == FAILURE) {
    4208           4 :                 return;
    4209             :         }
    4210          12 :         GET_REFLECTION_OBJECT_PTR(ce);
    4211           6 :         if (ce->type == ZEND_USER_CLASS) {
    4212           4 :                 RETURN_LONG(ce->info.user.line_end);
    4213             :         }
    4214           2 :         RETURN_FALSE;
    4215             : }
    4216             : /* }}} */
    4217             : 
    4218             : /* {{{ proto public string ReflectionClass::getDocComment()
    4219             :    Returns the doc comment for this class */
    4220          17 : ZEND_METHOD(reflection_class, getDocComment)
    4221             : {
    4222             :         reflection_object *intern;
    4223             :         zend_class_entry *ce;
    4224             : 
    4225          17 :         if (zend_parse_parameters_none() == FAILURE) {
    4226           4 :                 return;
    4227             :         }
    4228          26 :         GET_REFLECTION_OBJECT_PTR(ce);
    4229          13 :         if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) {
    4230           7 :                 RETURN_STR_COPY(ce->info.user.doc_comment);
    4231             :         }
    4232           6 :         RETURN_FALSE;
    4233             : }
    4234             : /* }}} */
    4235             : 
    4236             : /* {{{ proto public ReflectionMethod ReflectionClass::getConstructor()
    4237             :    Returns the class' constructor if there is one, NULL otherwise */
    4238          37 : ZEND_METHOD(reflection_class, getConstructor)
    4239             : {
    4240             :         reflection_object *intern;
    4241             :         zend_class_entry *ce;
    4242             : 
    4243          37 :         if (zend_parse_parameters_none() == FAILURE) {
    4244           8 :                 return;
    4245             :         }
    4246          58 :         GET_REFLECTION_OBJECT_PTR(ce);
    4247             : 
    4248          29 :         if (ce->constructor) {
    4249          24 :                 reflection_method_factory(ce, ce->constructor, NULL, return_value);
    4250             :         } else {
    4251           5 :                 RETURN_NULL();
    4252             :         }
    4253             : }
    4254             : /* }}} */
    4255             : 
    4256             : /* {{{ proto public bool ReflectionClass::hasMethod(string name)
    4257             :    Returns whether a method exists or not */
    4258          42 : ZEND_METHOD(reflection_class, hasMethod)
    4259             : {
    4260             :         reflection_object *intern;
    4261             :         zend_class_entry *ce;
    4262             :         char *name, *lc_name;
    4263             :         size_t name_len;
    4264             : 
    4265          84 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4266          42 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
    4267           4 :                 return;
    4268             :         }
    4269             : 
    4270          76 :         GET_REFLECTION_OBJECT_PTR(ce);
    4271          38 :         lc_name = zend_str_tolower_dup(name, name_len);
    4272          76 :         if ((ce == zend_ce_closure && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
    4273           3 :                 && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0)
    4274          35 :                 || zend_hash_str_exists(&ce->function_table, lc_name, name_len)) {
    4275          27 :                 efree(lc_name);
    4276          27 :                 RETURN_TRUE;
    4277             :         } else {
    4278          11 :                 efree(lc_name);
    4279          11 :                 RETURN_FALSE;
    4280             :         }
    4281             : }
    4282             : /* }}} */
    4283             : 
    4284             : /* {{{ proto public ReflectionMethod ReflectionClass::getMethod(string name) throws ReflectionException
    4285             :    Returns the class' method specified by its name */
    4286          55 : ZEND_METHOD(reflection_class, getMethod)
    4287             : {
    4288             :         reflection_object *intern;
    4289             :         zend_class_entry *ce;
    4290             :         zend_function *mptr;
    4291             :         zval obj_tmp;
    4292             :         char *name, *lc_name;
    4293             :         size_t name_len;
    4294             : 
    4295         110 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4296          55 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
    4297           4 :                 return;
    4298             :         }
    4299             : 
    4300         102 :         GET_REFLECTION_OBJECT_PTR(ce);
    4301          51 :         lc_name = zend_str_tolower_dup(name, name_len);
    4302          62 :         if (ce == zend_ce_closure && !Z_ISUNDEF(intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
    4303             :                 && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
    4304           4 :                 && (mptr = zend_get_closure_invoke_method(Z_OBJ(intern->obj))) != NULL)
    4305             :         {
    4306             :                 /* don't assign closure_object since we only reflect the invoke handler
    4307             :                    method and not the closure definition itself */
    4308           2 :                 reflection_method_factory(ce, mptr, NULL, return_value);
    4309           2 :                 efree(lc_name);
    4310          64 :         } else if (ce == zend_ce_closure && Z_ISUNDEF(intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
    4311             :                 && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
    4312           9 :                 && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(Z_OBJ(obj_tmp))) != NULL) {
    4313             :                 /* don't assign closure_object since we only reflect the invoke handler
    4314             :                    method and not the closure definition itself */
    4315           3 :                 reflection_method_factory(ce, mptr, NULL, return_value);
    4316             :                 zval_dtor(&obj_tmp);
    4317           3 :                 efree(lc_name);
    4318          92 :         } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lc_name, name_len)) != NULL) {
    4319          36 :                 reflection_method_factory(ce, mptr, NULL, return_value);
    4320          36 :                 efree(lc_name);
    4321             :         } else {
    4322          10 :                 efree(lc_name);
    4323          10 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    4324             :                                 "Method %s does not exist", name);
    4325          10 :                 return;
    4326             :         }
    4327             : }
    4328             : /* }}} */
    4329             : 
    4330             : /* {{{ _addmethod */
    4331         274 : static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter, zval *obj)
    4332             : {
    4333             :         zval method;
    4334         274 :         size_t len = ZSTR_LEN(mptr->common.function_name);
    4335             :         zend_function *closure;
    4336         274 :         if (mptr->common.fn_flags & filter) {
    4337         256 :                 if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
    4338           1 :                         && memcmp(ZSTR_VAL(mptr->common.function_name), ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
    4339           2 :                         && (closure = zend_get_closure_invoke_method(Z_OBJ_P(obj))) != NULL)
    4340             :                 {
    4341           1 :                         mptr = closure;
    4342             :                 }
    4343             :                 /* don't assign closure_object since we only reflect the invoke handler
    4344             :                    method and not the closure definition itself, even if we have a
    4345             :                    closure */
    4346         254 :                 reflection_method_factory(ce, mptr, NULL, &method);
    4347         254 :                 add_next_index_zval(retval, &method);
    4348             :         }
    4349         274 : }
    4350             : /* }}} */
    4351             : 
    4352             : /* {{{ _addmethod */
    4353         273 : static int _addmethod_va(zval *el, int num_args, va_list args, zend_hash_key *hash_key)
    4354             : {
    4355         273 :         zend_function *mptr = (zend_function*)Z_PTR_P(el);
    4356         273 :         zend_class_entry *ce = *va_arg(args, zend_class_entry**);
    4357         273 :         zval *retval = va_arg(args, zval*);
    4358         273 :         long filter = va_arg(args, long);
    4359         273 :         zval *obj = va_arg(args, zval *);
    4360             : 
    4361         273 :         _addmethod(mptr, ce, retval, filter, obj);
    4362         273 :         return ZEND_HASH_APPLY_KEEP;
    4363             : }
    4364             : /* }}} */
    4365             : 
    4366             : /* {{{ proto public ReflectionMethod[] ReflectionClass::getMethods([long $filter])
    4367             :    Returns an array of this class' methods */
    4368          39 : ZEND_METHOD(reflection_class, getMethods)
    4369             : {
    4370             :         reflection_object *intern;
    4371             :         zend_class_entry *ce;
    4372          39 :         zend_long filter = 0;
    4373          39 :         int argc = ZEND_NUM_ARGS();
    4374             : 
    4375          78 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4376          39 :         if (argc) {
    4377           7 :                 if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) {
    4378           2 :                         return;
    4379             :                 }
    4380             :         } else {
    4381             :                 /* No parameters given, default to "return all" */
    4382          32 :                 filter = ZEND_ACC_PPP_MASK | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL | ZEND_ACC_STATIC;
    4383             :         }
    4384             : 
    4385          74 :         GET_REFLECTION_OBJECT_PTR(ce);
    4386             : 
    4387          37 :         array_init(return_value);
    4388          37 :         zend_hash_apply_with_arguments(&ce->function_table, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter, intern->obj);
    4389          74 :         if (Z_TYPE(intern->obj) != IS_UNDEF && instanceof_function(ce, zend_ce_closure)) {
    4390           1 :                 zend_function *closure = zend_get_closure_invoke_method(Z_OBJ(intern->obj));
    4391           1 :                 if (closure) {
    4392           1 :                         _addmethod(closure, ce, return_value, filter, &intern->obj);
    4393           1 :                         _free_function(closure);
    4394             :                 }
    4395             :         }
    4396             : }
    4397             : /* }}} */
    4398             : 
    4399             : /* {{{ proto public bool ReflectionClass::hasProperty(string name)
    4400             :    Returns whether a property exists or not */
    4401          43 : ZEND_METHOD(reflection_class, hasProperty)
    4402             : {
    4403             :         reflection_object *intern;
    4404             :         zend_property_info *property_info;
    4405             :         zend_class_entry *ce;
    4406             :         zend_string *name;
    4407             :         zval property;
    4408             : 
    4409          86 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4410          43 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
    4411           4 :                 return;
    4412             :         }
    4413             : 
    4414          78 :         GET_REFLECTION_OBJECT_PTR(ce);
    4415          78 :         if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) {
    4416          20 :                 if (property_info->flags & ZEND_ACC_SHADOW) {
    4417           2 :                         RETURN_FALSE;
    4418             :                 }
    4419          18 :                 RETURN_TRUE;
    4420             :         } else {
    4421          38 :                 if (Z_TYPE(intern->obj) != IS_UNDEF && Z_OBJ_HANDLER(intern->obj, has_property)) {
    4422           2 :                         ZVAL_STR_COPY(&property, name);
    4423           2 :                         if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, NULL)) {
    4424           0 :                                 zval_ptr_dtor(&property);
    4425           0 :                                 RETURN_TRUE;
    4426             :                         }
    4427           2 :                         zval_ptr_dtor(&property);
    4428             :                 }
    4429          19 :                 RETURN_FALSE;
    4430             :         }
    4431             : }
    4432             : /* }}} */
    4433             : 
    4434             : /* {{{ proto public ReflectionProperty ReflectionClass::getProperty(string name) throws ReflectionException
    4435             :    Returns the class' property specified by its name */
    4436         106 : ZEND_METHOD(reflection_class, getProperty)
    4437             : {
    4438             :         reflection_object *intern;
    4439             :         zend_class_entry *ce, *ce2;
    4440             :         zend_property_info *property_info;
    4441             :         zend_string *name, *classname;
    4442             :         char *tmp, *str_name;
    4443             :         size_t classname_len, str_name_len;
    4444             : 
    4445         212 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4446         106 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
    4447           4 :                 return;
    4448             :         }
    4449             : 
    4450         204 :         GET_REFLECTION_OBJECT_PTR(ce);
    4451         204 :         if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) {
    4452          46 :                 if ((property_info->flags & ZEND_ACC_SHADOW) == 0) {
    4453          40 :                         reflection_property_factory(ce, property_info, return_value);
    4454          40 :                         return;
    4455             :                 }
    4456         112 :         } else if (Z_TYPE(intern->obj) != IS_UNDEF) {
    4457             :                 /* Check for dynamic properties */
    4458           5 :                 if (zend_hash_exists(Z_OBJ_HT(intern->obj)->get_properties(&intern->obj), name)) {
    4459             :                         zend_property_info property_info_tmp;
    4460           5 :                         property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC;
    4461          10 :                         property_info_tmp.name = zend_string_copy(name);
    4462           5 :                         property_info_tmp.doc_comment = NULL;
    4463           5 :                         property_info_tmp.ce = ce;
    4464             : 
    4465           5 :                         reflection_property_factory(ce, &property_info_tmp, return_value);
    4466           5 :                         intern = Z_REFLECTION_P(return_value);
    4467           5 :                         intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY;
    4468           5 :                         return;
    4469             :                 }
    4470             :         }
    4471          57 :         str_name = ZSTR_VAL(name);
    4472          57 :         str_name_len = ZSTR_LEN(name);
    4473          57 :         if ((tmp = strstr(ZSTR_VAL(name), "::")) != NULL) {
    4474          33 :                 classname_len = tmp - ZSTR_VAL(name);
    4475          33 :                 classname = zend_string_alloc(classname_len, 0);
    4476          33 :                 zend_str_tolower_copy(ZSTR_VAL(classname), ZSTR_VAL(name), classname_len);
    4477          33 :                 ZSTR_VAL(classname)[classname_len] = '\0';
    4478          33 :                 str_name_len = ZSTR_LEN(name) - (classname_len + 2);
    4479          33 :                 str_name = tmp + 2;
    4480             : 
    4481          33 :                 ce2 = zend_lookup_class(classname);
    4482          33 :                 if (!ce2) {
    4483           3 :                         if (!EG(exception)) {
    4484           3 :                                 zend_throw_exception_ex(reflection_exception_ptr, -1, "Class %s does not exist", ZSTR_VAL(classname));
    4485             :                         }
    4486             :                         zend_string_release(classname);
    4487           3 :                         return;
    4488             :                 }
    4489             :                 zend_string_release(classname);
    4490             : 
    4491          30 :                 if (!instanceof_function(ce, ce2)) {
    4492           8 :                         zend_throw_exception_ex(reflection_exception_ptr, -1, "Fully qualified property name %s::%s does not specify a base class of %s", ZSTR_VAL(ce2->name), str_name, ZSTR_VAL(ce->name));
    4493           8 :                         return;
    4494             :                 }
    4495          22 :                 ce = ce2;
    4496             : 
    4497          44 :                 if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, str_name, str_name_len)) != NULL && (property_info->flags & ZEND_ACC_SHADOW) == 0) {
    4498          20 :                         reflection_property_factory(ce, property_info, return_value);
    4499          20 :                         return;
    4500             :                 }
    4501             :         }
    4502          26 :         zend_throw_exception_ex(reflection_exception_ptr, 0,
    4503             :                         "Property %s does not exist", str_name);
    4504             : }
    4505             : /* }}} */
    4506             : 
    4507             : /* {{{ _addproperty */
    4508         103 : static int _addproperty(zval *el, int num_args, va_list args, zend_hash_key *hash_key)
    4509             : {
    4510             :         zval property;
    4511         103 :         zend_property_info *pptr = (zend_property_info*)Z_PTR_P(el);
    4512         103 :         zend_class_entry *ce = *va_arg(args, zend_class_entry**);
    4513         103 :         zval *retval = va_arg(args, zval*);
    4514         103 :         long filter = va_arg(args, long);
    4515             : 
    4516         103 :         if (pptr->flags      & ZEND_ACC_SHADOW) {
    4517           3 :                 return 0;
    4518             :         }
    4519             : 
    4520         100 :         if (pptr->flags      & filter) {
    4521          80 :                 reflection_property_factory(ce, pptr, &property);
    4522          80 :                 add_next_index_zval(retval, &property);
    4523             :         }
    4524         100 :         return 0;
    4525             : }
    4526             : /* }}} */
    4527             : 
    4528             : /* {{{ _adddynproperty */
    4529          16 : static int _adddynproperty(zval *ptr, int num_args, va_list args, zend_hash_key *hash_key)
    4530             : {
    4531             :         zval property;
    4532          16 :         zend_class_entry *ce = *va_arg(args, zend_class_entry**);
    4533          16 :         zval *retval = va_arg(args, zval*);
    4534             : 
    4535             :         /* under some circumstances, the properties hash table may contain numeric
    4536             :          * properties (e.g. when casting from array). This is a WONT FIX bug, at
    4537             :          * least for the moment. Ignore these */
    4538          16 :         if (hash_key->key == NULL) {
    4539           2 :                 return 0;
    4540             :         }
    4541             : 
    4542          14 :         if (ZSTR_VAL(hash_key->key)[0] == '\0') {
    4543           2 :                 return 0; /* non public cannot be dynamic */
    4544             :         }
    4545             : 
    4546          12 :         if (zend_get_property_info(ce, hash_key->key, 1) == NULL) {
    4547             :                 zend_property_info property_info;
    4548             : 
    4549          11 :                 property_info.doc_comment = NULL;
    4550          11 :                 property_info.flags = ZEND_ACC_IMPLICIT_PUBLIC;
    4551          11 :                 property_info.name = hash_key->key;
    4552          11 :                 property_info.ce = ce;
    4553          11 :                 property_info.offset = -1;
    4554          11 :                 reflection_property_factory(ce, &property_info, &property);
    4555          11 :                 add_next_index_zval(retval, &property);
    4556             :         }
    4557          12 :         return 0;
    4558             : }
    4559             : /* }}} */
    4560             : 
    4561             : /* {{{ proto public ReflectionProperty[] ReflectionClass::getProperties([long $filter])
    4562             :    Returns an array of this class' properties */
    4563          30 : ZEND_METHOD(reflection_class, getProperties)
    4564             : {
    4565             :         reflection_object *intern;
    4566             :         zend_class_entry *ce;
    4567          30 :         zend_long filter = 0;
    4568          30 :         int argc = ZEND_NUM_ARGS();
    4569             : 
    4570          60 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4571          30 :         if (argc) {
    4572           9 :                 if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) {
    4573           2 :                         return;
    4574             :                 }
    4575             :         } else {
    4576             :                 /* No parameters given, default to "return all" */
    4577          21 :                 filter = ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC;
    4578             :         }
    4579             : 
    4580          56 :         GET_REFLECTION_OBJECT_PTR(ce);
    4581             : 
    4582          28 :         array_init(return_value);
    4583          28 :         zend_hash_apply_with_arguments(&ce->properties_info, (apply_func_args_t) _addproperty, 3, &ce, return_value, filter);
    4584             : 
    4585          56 :         if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT(intern->obj)->get_properties) {
    4586           9 :                 HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(&intern->obj);
    4587           9 :                 zend_hash_apply_with_arguments(properties, (apply_func_args_t) _adddynproperty, 2, &ce, return_value);
    4588             :         }
    4589             : }
    4590             : /* }}} */
    4591             : 
    4592             : /* {{{ proto public bool ReflectionClass::hasConstant(string name)
    4593             :    Returns whether a constant exists or not */
    4594          17 : ZEND_METHOD(reflection_class, hasConstant)
    4595             : {
    4596             :         reflection_object *intern;
    4597             :         zend_class_entry *ce;
    4598             :         zend_string *name;
    4599             : 
    4600          34 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4601          17 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
    4602           4 :                 return;
    4603             :         }
    4604             : 
    4605          26 :         GET_REFLECTION_OBJECT_PTR(ce);
    4606          13 :         if (zend_hash_exists(&ce->constants_table, name)) {
    4607           4 :                 RETURN_TRUE;
    4608             :         } else {
    4609           9 :                 RETURN_FALSE;
    4610             :         }
    4611             : }
    4612             : /* }}} */
    4613             : 
    4614             : /* {{{ proto public array ReflectionClass::getConstants()
    4615             :    Returns an associative array containing this class' constants and their values */
    4616          24 : ZEND_METHOD(reflection_class, getConstants)
    4617             : {
    4618             :         reflection_object *intern;
    4619             :         zend_class_entry *ce;
    4620             :         zend_string *key;
    4621             :         zend_class_constant *c;
    4622             :         zval *val;
    4623             : 
    4624          24 :         if (zend_parse_parameters_none() == FAILURE) {
    4625           6 :                 return;
    4626             :         }
    4627          36 :         GET_REFLECTION_OBJECT_PTR(ce);
    4628          18 :         array_init(return_value);
    4629         290 :         ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
    4630         136 :                 if (UNEXPECTED(zval_update_constant_ex(&c->value, ce) != SUCCESS)) {
    4631           0 :                         zend_array_destroy(Z_ARRVAL_P(return_value));
    4632           0 :                         return;
    4633             :                 }
    4634         136 :                 val = zend_hash_add_new(Z_ARRVAL_P(return_value), key, &c->value);
    4635         136 :                 Z_TRY_ADDREF_P(val);
    4636             :         } ZEND_HASH_FOREACH_END();
    4637             : }
    4638             : /* }}} */
    4639             : 
    4640             : /* {{{ proto public array ReflectionClass::getReflectionConstants()
    4641             :    Returns an associative array containing this class' constants as ReflectionClassConstant objects */
    4642           1 : ZEND_METHOD(reflection_class, getReflectionConstants)
    4643             : {
    4644             :         reflection_object *intern;
    4645             :         zend_class_entry *ce;
    4646             :         zend_string *name;
    4647             :         zend_class_constant *constant;
    4648             : 
    4649           1 :         if (zend_parse_parameters_none() == FAILURE) {
    4650           0 :                 return;
    4651             :         }
    4652           2 :         GET_REFLECTION_OBJECT_PTR(ce);
    4653           1 :         array_init(return_value);
    4654          13 :         ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, name, constant) {
    4655             :                 zval class_const;
    4656           6 :                 reflection_class_constant_factory(ce, name, constant, &class_const);
    4657           6 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &class_const);
    4658             :         } ZEND_HASH_FOREACH_END();
    4659             : }
    4660             : /* }}} */
    4661             : 
    4662             : /* {{{ proto public mixed ReflectionClass::getConstant(string name)
    4663             :    Returns the class' constant specified by its name */
    4664          43 : ZEND_METHOD(reflection_class, getConstant)
    4665             : {
    4666             :         reflection_object *intern;
    4667             :         zend_class_entry *ce;
    4668             :         zend_class_constant *c;
    4669             :         zend_string *name;
    4670             : 
    4671          86 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4672          43 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
    4673           8 :                 return;
    4674             :         }
    4675             : 
    4676          70 :         GET_REFLECTION_OBJECT_PTR(ce);
    4677         115 :         ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) {
    4678          40 :                 if (UNEXPECTED(zval_update_constant_ex(&c->value, ce) != SUCCESS)) {
    4679           0 :                         return;
    4680             :                 }
    4681             :         } ZEND_HASH_FOREACH_END();
    4682          70 :         if ((c = zend_hash_find_ptr(&ce->constants_table, name)) == NULL) {
    4683          22 :                 RETURN_FALSE;
    4684             :         }
    4685          13 :         ZVAL_DUP(return_value, &c->value);
    4686             : }
    4687             : /* }}} */
    4688             : 
    4689             : /* {{{ proto public mixed ReflectionClass::getReflectionConstant(string name)
    4690             :    Returns the class' constant as ReflectionClassConstant objects */
    4691           0 : ZEND_METHOD(reflection_class, getReflectionConstant)
    4692             : {
    4693             :         reflection_object *intern;
    4694             :         zend_class_entry *ce;
    4695             :         zend_class_constant *constant;
    4696             :         zend_string *name;
    4697             : 
    4698           0 :         GET_REFLECTION_OBJECT_PTR(ce);
    4699           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
    4700           0 :                 return;
    4701             :         }
    4702             : 
    4703           0 :         if ((constant = zend_hash_find_ptr(&ce->constants_table, name)) == NULL) {
    4704           0 :                 RETURN_FALSE;
    4705             :         }
    4706           0 :         reflection_class_constant_factory(ce, name, constant, return_value);
    4707             : }
    4708             : /* }}} */
    4709             : 
    4710             : /* {{{ _class_check_flag */
    4711          43 : static void _class_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask)
    4712             : {
    4713             :         reflection_object *intern;
    4714             :         zend_class_entry *ce;
    4715             : 
    4716          43 :         if (zend_parse_parameters_none() == FAILURE) {
    4717           3 :                 return;
    4718             :         }
    4719          80 :         GET_REFLECTION_OBJECT_PTR(ce);
    4720          40 :         RETVAL_BOOL(ce->ce_flags & mask);
    4721             : }
    4722             : /* }}} */
    4723             : 
    4724             : /* {{{ proto public bool ReflectionClass::isInstantiable()
    4725             :    Returns whether this class is instantiable */
    4726          56 : ZEND_METHOD(reflection_class, isInstantiable)
    4727             : {
    4728             :         reflection_object *intern;
    4729             :         zend_class_entry *ce;
    4730             : 
    4731          56 :         if (zend_parse_parameters_none() == FAILURE) {
    4732           4 :                 return;
    4733             :         }
    4734         104 :         GET_REFLECTION_OBJECT_PTR(ce);
    4735          52 :         if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
    4736           8 :                 RETURN_FALSE;
    4737             :         }
    4738             : 
    4739             :         /* Basically, the class is instantiable. Though, if there is a constructor
    4740             :          * and it is not publicly accessible, it isn't! */
    4741          44 :         if (!ce->constructor) {
    4742          29 :                 RETURN_TRUE;
    4743             :         }
    4744             : 
    4745          15 :         RETURN_BOOL(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC);
    4746             : }
    4747             : /* }}} */
    4748             : 
    4749             : /* {{{ proto public bool ReflectionClass::isCloneable()
    4750             :    Returns whether this class is cloneable */
    4751          14 : ZEND_METHOD(reflection_class, isCloneable)
    4752             : {
    4753             :         reflection_object *intern;
    4754             :         zend_class_entry *ce;
    4755             :         zval obj;
    4756             : 
    4757          14 :         if (zend_parse_parameters_none() == FAILURE) {
    4758           0 :                 return;
    4759             :         }
    4760          28 :         GET_REFLECTION_OBJECT_PTR(ce);
    4761          14 :         if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) {
    4762           4 :                 RETURN_FALSE;
    4763             :         }
    4764          20 :         if (!Z_ISUNDEF(intern->obj)) {
    4765           5 :                 if (ce->clone) {
    4766           1 :                         RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC);
    4767             :                 } else {
    4768           4 :                         RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL);
    4769             :                 }
    4770             :         } else {
    4771           5 :                 if (ce->clone) {
    4772           1 :                         RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC);
    4773             :                 } else {
    4774           4 :                         if (UNEXPECTED(object_init_ex(&obj, ce) != SUCCESS)) {
    4775           0 :                                 return;
    4776             :                         }
    4777           4 :                         RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL);
    4778             :                         zval_dtor(&obj);
    4779             :                 }
    4780             :         }
    4781             : }
    4782             : /* }}} */
    4783             : 
    4784             : /* {{{ proto public bool ReflectionClass::isInterface()
    4785             :    Returns whether this is an interface or a class */
    4786          13 : ZEND_METHOD(reflection_class, isInterface)
    4787             : {
    4788          13 :         _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_INTERFACE);
    4789          13 : }
    4790             : /* }}} */
    4791             : 
    4792             : /* {{{ proto public bool ReflectionClass::isTrait()
    4793             :    Returns whether this is a trait */
    4794           5 : ZEND_METHOD(reflection_class, isTrait)
    4795             : {
    4796           5 :         _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT);
    4797           5 : }
    4798             : /* }}} */
    4799             : 
    4800             : /* {{{ proto public bool ReflectionClass::isFinal()
    4801             :    Returns whether this class is final */
    4802          12 : ZEND_METHOD(reflection_class, isFinal)
    4803             : {
    4804          12 :         _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL);
    4805          12 : }
    4806             : /* }}} */
    4807             : 
    4808             : /* {{{ proto public bool ReflectionClass::isAbstract()
    4809             :    Returns whether this class is abstract */
    4810          13 : ZEND_METHOD(reflection_class, isAbstract)
    4811             : {
    4812          13 :         _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
    4813          13 : }
    4814             : /* }}} */
    4815             : 
    4816             : /* {{{ proto public int ReflectionClass::getModifiers()
    4817             :    Returns a bitfield of the access modifiers for this class */
    4818          21 : ZEND_METHOD(reflection_class, getModifiers)
    4819             : {
    4820             :         reflection_object *intern;
    4821             :         zend_class_entry *ce;
    4822             : 
    4823          21 :         if (zend_parse_parameters_none() == FAILURE) {
    4824           1 :                 return;
    4825             :         }
    4826          40 :         GET_REFLECTION_OBJECT_PTR(ce);
    4827             : 
    4828          20 :         RETURN_LONG(ce->ce_flags & ~(ZEND_ACC_CONSTANTS_UPDATED|ZEND_ACC_USE_GUARDS));
    4829             : }
    4830             : /* }}} */
    4831             : 
    4832             : /* {{{ proto public bool ReflectionClass::isInstance(stdclass object)
    4833             :    Returns whether the given object is an instance of this class */
    4834          59 : ZEND_METHOD(reflection_class, isInstance)
    4835             : {
    4836             :         reflection_object *intern;
    4837             :         zend_class_entry *ce;
    4838             :         zval *object;
    4839             : 
    4840         118 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4841          59 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &object) == FAILURE) {
    4842          14 :                 return;
    4843             :         }
    4844          90 :         GET_REFLECTION_OBJECT_PTR(ce);
    4845          45 :         RETURN_BOOL(instanceof_function(Z_OBJCE_P(object), ce));
    4846             : }
    4847             : /* }}} */
    4848             : 
    4849             : /* {{{ proto public stdclass ReflectionClass::newInstance(mixed* args, ...)
    4850             :    Returns an instance of this class */
    4851          50 : ZEND_METHOD(reflection_class, newInstance)
    4852             : {
    4853             :         zval retval;
    4854             :         reflection_object *intern;
    4855             :         zend_class_entry *ce, *old_scope;
    4856             :         zend_function *constructor;
    4857             : 
    4858         100 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4859         100 :         GET_REFLECTION_OBJECT_PTR(ce);
    4860             : 
    4861          50 :         if (UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) {
    4862           1 :                 return;
    4863             :         }
    4864             : 
    4865          49 :         old_scope = EG(fake_scope);
    4866          49 :         EG(fake_scope) = ce;
    4867          49 :         constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value));
    4868          49 :         EG(fake_scope) = old_scope;
    4869             : 
    4870             :         /* Run the constructor if there is one */
    4871          49 :         if (constructor) {
    4872          24 :                 zval *params = NULL;
    4873          24 :                 int ret, i, num_args = 0;
    4874             :                 zend_fcall_info fci;
    4875             :                 zend_fcall_info_cache fcc;
    4876             : 
    4877          24 :                 if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
    4878           2 :                         zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of class %s", ZSTR_VAL(ce->name));
    4879             :                         zval_dtor(return_value);
    4880           2 :                         RETURN_NULL();
    4881             :                 }
    4882             : 
    4883          22 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &params, &num_args) == FAILURE) {
    4884             :                         zval_dtor(return_value);
    4885           0 :                         RETURN_FALSE;
    4886             :                 }
    4887             : 
    4888          54 :                 for (i = 0; i < num_args; i++) {
    4889          32 :                         if (Z_REFCOUNTED(params[i])) Z_ADDREF(params[i]);
    4890             :                 }
    4891             : 
    4892          22 :                 fci.size = sizeof(fci);
    4893          22 :                 ZVAL_UNDEF(&fci.function_name);
    4894          22 :                 fci.object = Z_OBJ_P(return_value);
    4895          22 :                 fci.retval = &retval;
    4896          22 :                 fci.param_count = num_args;
    4897          22 :                 fci.params = params;
    4898          22 :                 fci.no_separation = 1;
    4899             : 
    4900          22 :                 fcc.initialized = 1;
    4901          22 :                 fcc.function_handler = constructor;
    4902          22 :                 fcc.calling_scope = zend_get_executed_scope();;
    4903          22 :                 fcc.called_scope = Z_OBJCE_P(return_value);
    4904          22 :                 fcc.object = Z_OBJ_P(return_value);
    4905             : 
    4906          22 :                 ret = zend_call_function(&fci, &fcc);
    4907          22 :                 zval_ptr_dtor(&retval);
    4908          54 :                 for (i = 0; i < num_args; i++) {
    4909          32 :                         zval_ptr_dtor(&params[i]);
    4910             :                 }
    4911          22 :                 if (ret == FAILURE) {
    4912           1 :                         php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name));
    4913             :                         zval_dtor(return_value);
    4914           1 :                         RETURN_NULL();
    4915             :                 }
    4916          25 :         } else if (ZEND_NUM_ARGS()) {
    4917           3 :                 zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ZSTR_VAL(ce->name));
    4918             :         }
    4919             : }
    4920             : /* }}} */
    4921             : 
    4922             : /* {{{ proto public stdclass ReflectionClass::newInstanceWithoutConstructor()
    4923             :    Returns an instance of this class without invoking its constructor */
    4924           5 : ZEND_METHOD(reflection_class, newInstanceWithoutConstructor)
    4925             : {
    4926             :         reflection_object *intern;
    4927             :         zend_class_entry *ce;
    4928             : 
    4929          10 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4930          10 :         GET_REFLECTION_OBJECT_PTR(ce);
    4931             : 
    4932           5 :         if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL) {
    4933           2 :                 zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s is an internal class marked as final that cannot be instantiated without invoking its constructor", ZSTR_VAL(ce->name));
    4934           2 :                 return;
    4935             :         }
    4936             : 
    4937           3 :         object_init_ex(return_value, ce);
    4938             : }
    4939             : /* }}} */
    4940             : 
    4941             : /* {{{ proto public stdclass ReflectionClass::newInstanceArgs([array args])
    4942             :    Returns an instance of this class */
    4943          18 : ZEND_METHOD(reflection_class, newInstanceArgs)
    4944             : {
    4945             :         zval retval, *val;
    4946             :         reflection_object *intern;
    4947             :         zend_class_entry *ce, *old_scope;
    4948          18 :         int ret, i, argc = 0;
    4949             :         HashTable *args;
    4950             :         zend_function *constructor;
    4951             : 
    4952             : 
    4953          36 :         METHOD_NOTSTATIC(reflection_class_ptr);
    4954          36 :         GET_REFLECTION_OBJECT_PTR(ce);
    4955             : 
    4956          18 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|h", &args) == FAILURE) {
    4957           0 :                 return;
    4958             :         }
    4959             : 
    4960          18 :         if (ZEND_NUM_ARGS() > 0) {
    4961          11 :                 argc = args->nNumOfElements;
    4962             :         }
    4963             : 
    4964          18 :         if (UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) {
    4965           0 :                 return;
    4966             :         }
    4967             : 
    4968          18 :         old_scope = EG(fake_scope);
    4969          18 :         EG(fake_scope) = ce;
    4970          18 :         constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value));
    4971          18 :         EG(fake_scope) = old_scope;
    4972             : 
    4973             :         /* Run the constructor if there is one */
    4974          18 :         if (constructor) {
    4975          14 :                 zval *params = NULL;
    4976             :                 zend_fcall_info fci;
    4977             :                 zend_fcall_info_cache fcc;
    4978             : 
    4979          14 :                 if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
    4980           2 :                         zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of class %s", ZSTR_VAL(ce->name));
    4981             :                         zval_dtor(return_value);
    4982           2 :                         RETURN_NULL();
    4983             :                 }
    4984             : 
    4985          12 :                 if (argc) {
    4986           7 :                         params = safe_emalloc(sizeof(zval), argc, 0);
    4987           7 :                         argc = 0;
    4988          35 :                         ZEND_HASH_FOREACH_VAL(args, val) {
    4989          14 :                                 ZVAL_COPY(&params[argc], val);
    4990          14 :                                 argc++;
    4991             :                         } ZEND_HASH_FOREACH_END();
    4992             :                 }
    4993             : 
    4994          12 :                 fci.size = sizeof(fci);
    4995          12 :                 ZVAL_UNDEF(&fci.function_name);
    4996          12 :                 fci.object = Z_OBJ_P(return_value);
    4997          12 :                 fci.retval = &retval;
    4998          12 :                 fci.param_count = argc;
    4999          12 :                 fci.params = params;
    5000          12 :                 fci.no_separation = 1;
    5001             : 
    5002          12 :                 fcc.initialized = 1;
    5003          12 :                 fcc.function_handler = constructor;
    5004          12 :                 fcc.calling_scope = zend_get_executed_scope();
    5005          12 :                 fcc.called_scope = Z_OBJCE_P(return_value);
    5006          12 :                 fcc.object = Z_OBJ_P(return_value);
    5007             : 
    5008          12 :                 ret = zend_call_function(&fci, &fcc);
    5009          12 :                 zval_ptr_dtor(&retval);
    5010          12 :                 if (params) {
    5011          21 :                         for (i = 0; i < argc; i++) {
    5012          14 :                                 zval_ptr_dtor(&params[i]);
    5013             :                         }
    5014           7 :                         efree(params);
    5015             :                 }
    5016          12 :                 if (ret == FAILURE) {
    5017           1 :                         zval_ptr_dtor(&retval);
    5018           1 :                         php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name));
    5019             :                         zval_dtor(return_value);
    5020           1 :                         RETURN_NULL();
    5021             :                 }
    5022           4 :         } else if (argc) {
    5023           2 :                 zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ZSTR_VAL(ce->name));
    5024             :         }
    5025             : }
    5026             : /* }}} */
    5027             : 
    5028             : /* {{{ proto public ReflectionClass[] ReflectionClass::getInterfaces()
    5029             :    Returns an array of interfaces this class implements */
    5030          25 : ZEND_METHOD(reflection_class, getInterfaces)
    5031             : {
    5032             :         reflection_object *intern;
    5033             :         zend_class_entry *ce;
    5034             : 
    5035          25 :         if (zend_parse_parameters_none() == FAILURE) {
    5036           4 :                 return;
    5037             :         }
    5038          42 :         GET_REFLECTION_OBJECT_PTR(ce);
    5039             : 
    5040             :         /* Return an empty array if this class implements no interfaces */
    5041          21 :         array_init(return_value);
    5042             : 
    5043          21 :         if (ce->num_interfaces) {
    5044             :                 uint32_t i;
    5045             : 
    5046          58 :                 for (i=0; i < ce->num_interfaces; i++) {
    5047             :                         zval interface;
    5048          45 :                         zend_reflection_class_factory(ce->interfaces[i], &interface);
    5049          45 :                         zend_hash_update(Z_ARRVAL_P(return_value), ce->interfaces[i]->name, &interface);
    5050             :                 }
    5051             :         }
    5052             : }
    5053             : /* }}} */
    5054             : 
    5055             : /* {{{ proto public String[] ReflectionClass::getInterfaceNames()
    5056             :    Returns an array of names of interfaces this class implements */
    5057           1 : ZEND_METHOD(reflection_class, getInterfaceNames)
    5058             : {
    5059             :         reflection_object *intern;
    5060             :         zend_class_entry *ce;
    5061             :         uint32_t i;
    5062             : 
    5063           1 :         if (zend_parse_parameters_none() == FAILURE) {
    5064           0 :                 return;
    5065             :         }
    5066           2 :         GET_REFLECTION_OBJECT_PTR(ce);
    5067             : 
    5068             :         /* Return an empty array if this class implements no interfaces */
    5069           1 :         array_init(return_value);
    5070             : 
    5071           3 :         for (i=0; i < ce->num_interfaces; i++) {
    5072           4 :                 add_next_index_str(return_value, zend_string_copy(ce->interfaces[i]->name));
    5073             :         }
    5074             : }
    5075             : /* }}} */
    5076             : 
    5077             : /* {{{ proto public ReflectionClass[] ReflectionClass::getTraits()
    5078             :    Returns an array of traits used by this class */
    5079           4 : ZEND_METHOD(reflection_class, getTraits)
    5080             : {
    5081             :         reflection_object *intern;
    5082             :         zend_class_entry *ce;
    5083             :         uint32_t i;
    5084             : 
    5085           4 :         if (zend_parse_parameters_none() == FAILURE) {
    5086           0 :                 return;
    5087             :         }
    5088           8 :         GET_REFLECTION_OBJECT_PTR(ce);
    5089             : 
    5090           4 :         array_init(return_value);
    5091             : 
    5092           9 :         for (i=0; i < ce->num_traits; i++) {
    5093             :                 zval trait;
    5094           5 :                 zend_reflection_class_factory(ce->traits[i], &trait);
    5095           5 :                 zend_hash_update(Z_ARRVAL_P(return_value), ce->traits[i]->name, &trait);
    5096             :         }
    5097             : }
    5098             : /* }}} */
    5099             : 
    5100             : /* {{{ proto public String[] ReflectionClass::getTraitNames()
    5101             :    Returns an array of names of traits used by this class */
    5102           3 : ZEND_METHOD(reflection_class, getTraitNames)
    5103             : {
    5104             :         reflection_object *intern;
    5105             :         zend_class_entry *ce;
    5106             :         uint32_t i;
    5107             : 
    5108           3 :         if (zend_parse_parameters_none() == FAILURE) {
    5109           0 :                 return;
    5110             :         }
    5111           6 :         GET_REFLECTION_OBJECT_PTR(ce);
    5112             : 
    5113           3 :         array_init(return_value);
    5114             : 
    5115           6 :         for (i=0; i < ce->num_traits; i++) {
    5116           6 :                 add_next_index_str(return_value, zend_string_copy(ce->traits[i]->name));
    5117             :         }
    5118             : }
    5119             : /* }}} */
    5120             : 
    5121             : /* {{{ proto public arra ReflectionClass::getTraitaliases()
    5122             :    Returns an array of trait aliases */
    5123           6 : ZEND_METHOD(reflection_class, getTraitAliases)
    5124             : {
    5125             :         reflection_object *intern;
    5126             :         zend_class_entry *ce;
    5127             : 
    5128           6 :         if (zend_parse_parameters_none() == FAILURE) {
    5129           0 :                 return;
    5130             :         }
    5131          12 :         GET_REFLECTION_OBJECT_PTR(ce);
    5132             : 
    5133           6 :         array_init(return_value);
    5134             : 
    5135           6 :         if (ce->trait_aliases) {
    5136           4 :                 uint32_t i = 0;
    5137          14 :                 while (ce->trait_aliases[i]) {
    5138             :                         zend_string *mname;
    5139           6 :                         zend_trait_method_reference *cur_ref = ce->trait_aliases[i]->trait_method;
    5140             : 
    5141           6 :                         if (ce->trait_aliases[i]->alias) {
    5142             : 
    5143          10 :                                 mname = zend_string_alloc(ZSTR_LEN(cur_ref->ce->name) + ZSTR_LEN(cur_ref->method_name) + 2, 0);
    5144           5 :                                 snprintf(ZSTR_VAL(mname), ZSTR_LEN(mname) + 1, "%s::%s", ZSTR_VAL(cur_ref->ce->name), ZSTR_VAL(cur_ref->method_name));
    5145           5 :                                 add_assoc_str_ex(return_value, ZSTR_VAL(ce->trait_aliases[i]->alias), ZSTR_LEN(ce->trait_aliases[i]->alias), mname);
    5146             :                         }
    5147           6 :                         i++;
    5148             :                 }
    5149             :         }
    5150             : }
    5151             : /* }}} */
    5152             : 
    5153             : /* {{{ proto public ReflectionClass ReflectionClass::getParentClass()
    5154             :    Returns the class' parent class, or, if none exists, FALSE */
    5155          10 : ZEND_METHOD(reflection_class, getParentClass)
    5156             : {
    5157             :         reflection_object *intern;
    5158             :         zend_class_entry *ce;
    5159             : 
    5160          10 :         if (zend_parse_parameters_none() == FAILURE) {
    5161           3 :                 return;
    5162             :         }
    5163          14 :         GET_REFLECTION_OBJECT_PTR(ce);
    5164             : 
    5165           7 :         if (ce->parent) {
    5166           2 :                 zend_reflection_class_factory(ce->parent, return_value);
    5167             :         } else {
    5168           5 :                 RETURN_FALSE;
    5169             :         }
    5170             : }
    5171             : /* }}} */
    5172             : 
    5173             : /* {{{ proto public bool ReflectionClass::isSubclassOf(string|ReflectionClass class)
    5174             :    Returns whether this class is a subclass of another class */
    5175         123 : ZEND_METHOD(reflection_class, isSubclassOf)
    5176             : {
    5177             :         reflection_object *intern, *argument;
    5178             :         zend_class_entry *ce, *class_ce;
    5179             :         zval *class_name;
    5180             : 
    5181         246 :         METHOD_NOTSTATIC(reflection_class_ptr);
    5182         246 :         GET_REFLECTION_OBJECT_PTR(ce);
    5183             : 
    5184         123 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &class_name) == FAILURE) {
    5185           8 :                 return;
    5186             :         }
    5187             : 
    5188         230 :         switch (Z_TYPE_P(class_name)) {
    5189             :                 case IS_STRING:
    5190          49 :                         if ((class_ce = zend_lookup_class(Z_STR_P(class_name))) == NULL) {
    5191           4 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    5192           4 :                                                 "Class %s does not exist", Z_STRVAL_P(class_name));
    5193           4 :                                 return;
    5194             :                         }
    5195          45 :                         break;
    5196             :                 case IS_OBJECT:
    5197          62 :                         if (instanceof_function(Z_OBJCE_P(class_name), reflection_class_ptr)) {
    5198          62 :                                 argument = Z_REFLECTION_P(class_name);
    5199          62 :                                 if (argument->ptr == NULL) {
    5200           0 :                                         zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object");
    5201           0 :                                         return;
    5202             :                                 }
    5203          62 :                                 class_ce = argument->ptr;
    5204          62 :                                 break;
    5205             :                         }
    5206             :                         /* no break */
    5207             :                 default:
    5208           4 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    5209             :                                         "Parameter one must either be a string or a ReflectionClass object");
    5210           4 :                         return;
    5211             :         }
    5212             : 
    5213         107 :         RETURN_BOOL((ce != class_ce && instanceof_function(ce, class_ce)));
    5214             : }
    5215             : /* }}} */
    5216             : 
    5217             : /* {{{ proto public bool ReflectionClass::implementsInterface(string|ReflectionClass interface_name)
    5218             :    Returns whether this class is a subclass of another class */
    5219          56 : ZEND_METHOD(reflection_class, implementsInterface)
    5220             : {
    5221             :         reflection_object *intern, *argument;
    5222             :         zend_class_entry *ce, *interface_ce;
    5223             :         zval *interface;
    5224             : 
    5225         112 :         METHOD_NOTSTATIC(reflection_class_ptr);
    5226         112 :         GET_REFLECTION_OBJECT_PTR(ce);
    5227             : 
    5228          56 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &interface) == FAILURE) {
    5229           2 :                 return;
    5230             :         }
    5231             : 
    5232         108 :         switch (Z_TYPE_P(interface)) {
    5233             :                 case IS_STRING:
    5234          27 :                         if ((interface_ce = zend_lookup_class(Z_STR_P(interface))) == NULL) {
    5235           2 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    5236           2 :                                                 "Interface %s does not exist", Z_STRVAL_P(interface));
    5237           2 :                                 return;
    5238             :                         }
    5239          25 :                         break;
    5240             :                 case IS_OBJECT:
    5241          25 :                         if (instanceof_function(Z_OBJCE_P(interface), reflection_class_ptr)) {
    5242          25 :                                 argument = Z_REFLECTION_P(interface);
    5243          25 :                                 if (argument->ptr == NULL) {
    5244           0 :                                         zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object");
    5245           0 :                                         return;
    5246             :                                 }
    5247          25 :                                 interface_ce = argument->ptr;
    5248          25 :                                 break;
    5249             :                         }
    5250             :                         /* no break */
    5251             :                 default:
    5252           2 :                         zend_throw_exception_ex(reflection_exception_ptr, 0,
    5253             :                                         "Parameter one must either be a string or a ReflectionClass object");
    5254           2 :                         return;
    5255             :         }
    5256             : 
    5257          50 :         if (!(interface_ce->ce_flags & ZEND_ACC_INTERFACE)) {
    5258          30 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    5259          30 :                                 "Interface %s is a Class", ZSTR_VAL(interface_ce->name));
    5260          30 :                 return;
    5261             :         }
    5262          20 :         RETURN_BOOL(instanceof_function(ce, interface_ce));
    5263             : }
    5264             : /* }}} */
    5265             : 
    5266             : /* {{{ proto public bool ReflectionClass::isIterateable()
    5267             :    Returns whether this class is iterateable (can be used inside foreach) */
    5268          27 : ZEND_METHOD(reflection_class, isIterateable)
    5269             : {
    5270             :         reflection_object *intern;
    5271             :         zend_class_entry *ce;
    5272             : 
    5273          27 :         if (zend_parse_parameters_none() == FAILURE) {
    5274           7 :                 return;
    5275             :         }
    5276             : 
    5277          40 :         METHOD_NOTSTATIC(reflection_class_ptr);
    5278          40 :         GET_REFLECTION_OBJECT_PTR(ce);
    5279             : 
    5280          20 :         RETURN_BOOL(ce->get_iterator != NULL);
    5281             : }
    5282             : /* }}} */
    5283             : 
    5284             : /* {{{ proto public ReflectionExtension|NULL ReflectionClass::getExtension()
    5285             :    Returns NULL or the extension the class belongs to */
    5286           2 : ZEND_METHOD(reflection_class, getExtension)
    5287             : {
    5288             :         reflection_object *intern;
    5289             :         zend_class_entry *ce;
    5290             : 
    5291           2 :         if (zend_parse_parameters_none() == FAILURE) {
    5292           0 :                 return;
    5293             :         }
    5294             : 
    5295           4 :         METHOD_NOTSTATIC(reflection_class_ptr);
    5296           4 :         GET_REFLECTION_OBJECT_PTR(ce);
    5297             : 
    5298           2 :         if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) {
    5299           1 :                 reflection_extension_factory(return_value, ce->info.internal.module->name);
    5300             :         }
    5301             : }
    5302             : /* }}} */
    5303             : 
    5304             : /* {{{ proto public string|false ReflectionClass::getExtensionName()
    5305             :    Returns false or the name of the extension the class belongs to */
    5306           6 : ZEND_METHOD(reflection_class, getExtensionName)
    5307             : {
    5308             :         reflection_object *intern;
    5309             :         zend_class_entry *ce;
    5310             : 
    5311           6 :         if (zend_parse_parameters_none() == FAILURE) {
    5312           0 :                 return;
    5313             :         }
    5314             : 
    5315          12 :         METHOD_NOTSTATIC(reflection_class_ptr);
    5316          12 :         GET_REFLECTION_OBJECT_PTR(ce);
    5317             : 
    5318           6 :         if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) {
    5319          10 :                 RETURN_STRING(ce->info.internal.module->name);
    5320             :         } else {
    5321           1 :                 RETURN_FALSE;
    5322             :         }
    5323             : }
    5324             : /* }}} */
    5325             : 
    5326             : /* {{{ proto public bool ReflectionClass::inNamespace()
    5327             :    Returns whether this class is defined in namespace */
    5328           2 : ZEND_METHOD(reflection_class, inNamespace)
    5329             : {
    5330             :         zval *name;
    5331             :         const char *backslash;
    5332             : 
    5333           2 :         if (zend_parse_parameters_none() == FAILURE) {
    5334           0 :                 return;
    5335             :         }
    5336           4 :         if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) {
    5337           0 :                 RETURN_FALSE;
    5338             :         }
    5339           5 :         if (Z_TYPE_P(name) == IS_STRING
    5340           2 :                 && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name)))
    5341           1 :                 && backslash > Z_STRVAL_P(name))
    5342             :         {
    5343           1 :                 RETURN_TRUE;
    5344             :         }
    5345           1 :         RETURN_FALSE;
    5346             : }
    5347             : /* }}} */
    5348             : 
    5349             : /* {{{ proto public string ReflectionClass::getNamespaceName()
    5350             :    Returns the name of namespace where this class is defined */
    5351           2 : ZEND_METHOD(reflection_class, getNamespaceName)
    5352             : {
    5353             :         zval *name;
    5354             :         const char *backslash;
    5355             : 
    5356           2 :         if (zend_parse_parameters_none() == FAILURE) {
    5357           0 :                 return;
    5358             :         }
    5359           4 :         if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) {
    5360           0 :                 RETURN_FALSE;
    5361             :         }
    5362           5 :         if (Z_TYPE_P(name) == IS_STRING
    5363           2 :                 && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name)))
    5364           1 :                 && backslash > Z_STRVAL_P(name))
    5365             :         {
    5366           2 :                 RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name));
    5367             :         }
    5368           1 :         RETURN_EMPTY_STRING();
    5369             : }
    5370             : /* }}} */
    5371             : 
    5372             : /* {{{ proto public string ReflectionClass::getShortName()
    5373             :    Returns the short name of the class (without namespace part) */
    5374           2 : ZEND_METHOD(reflection_class, getShortName)
    5375             : {
    5376             :         zval *name;
    5377             :         const char *backslash;
    5378             : 
    5379           2 :         if (zend_parse_parameters_none() == FAILURE) {
    5380           0 :                 return;
    5381             :         }
    5382           4 :         if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) {
    5383           0 :                 RETURN_FALSE;
    5384             :         }
    5385           5 :         if (Z_TYPE_P(name) == IS_STRING
    5386           2 :                 && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name)))
    5387           1 :                 && backslash > Z_STRVAL_P(name))
    5388             :         {
    5389           2 :                 RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1));
    5390             :         }
    5391           1 :         ZVAL_DEREF(name);
    5392           1 :         ZVAL_COPY(return_value, name);
    5393             : }
    5394             : /* }}} */
    5395             : 
    5396             : /* {{{ proto public static mixed ReflectionObject::export(mixed argument [, bool return]) throws ReflectionException
    5397             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    5398           4 : ZEND_METHOD(reflection_object, export)
    5399             : {
    5400           4 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_object_ptr, 1);
    5401           4 : }
    5402             : /* }}} */
    5403             : 
    5404             : /* {{{ proto public void ReflectionObject::__construct(mixed argument) throws ReflectionException
    5405             :    Constructor. Takes an instance as an argument */
    5406         105 : ZEND_METHOD(reflection_object, __construct)
    5407             : {
    5408         105 :         reflection_class_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    5409         105 : }
    5410             : /* }}} */
    5411             : 
    5412             : /* {{{ proto public static mixed ReflectionProperty::export(mixed class, string name [, bool return]) throws ReflectionException
    5413             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    5414          14 : ZEND_METHOD(reflection_property, export)
    5415             : {
    5416          14 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_property_ptr, 2);
    5417          14 : }
    5418             : /* }}} */
    5419             : 
    5420             : /* {{{ proto public static mixed ReflectionClassConstant::export(mixed class, string name [, bool return]) throws ReflectionException
    5421             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    5422           8 : ZEND_METHOD(reflection_class_constant, export)
    5423             : {
    5424           8 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_class_constant_ptr, 2);
    5425           8 : }
    5426             : /* }}} */
    5427             : 
    5428             : /* {{{ proto public void ReflectionProperty::__construct(mixed class, string name)
    5429             :    Constructor. Throws an Exception in case the given property does not exist */
    5430          98 : ZEND_METHOD(reflection_property, __construct)
    5431             : {
    5432             :         zval propname, cname, *classname;
    5433             :         char *name_str;
    5434             :         size_t name_len;
    5435          98 :         int dynam_prop = 0;
    5436             :         zval *object;
    5437             :         reflection_object *intern;
    5438             :         zend_class_entry *ce;
    5439          98 :         zend_property_info *property_info = NULL;
    5440             :         property_reference *reference;
    5441             : 
    5442          98 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
    5443           3 :                 return;
    5444             :         }
    5445             : 
    5446         190 :         object = getThis();
    5447          95 :         intern = Z_REFLECTION_P(object);
    5448             : 
    5449             :         /* Find the class entry */
    5450         190 :         switch (Z_TYPE_P(classname)) {
    5451             :                 case IS_STRING:
    5452          80 :                         if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
    5453           3 :                                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    5454           3 :                                                 "Class %s does not exist", Z_STRVAL_P(classname));
    5455           3 :                                 return;
    5456             :                         }
    5457          77 :                         break;
    5458             : 
    5459             :                 case IS_OBJECT:
    5460          13 :                         ce = Z_OBJCE_P(classname);
    5461          13 :                         break;
    5462             : 
    5463             :                 default:
    5464           2 :                         _DO_THROW("The parameter class is expected to be either a string or an object");
    5465             :                         /* returns out of this function */
    5466             :         }
    5467             : 
    5468         180 :         if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, name_str, name_len)) == NULL || (property_info->flags & ZEND_ACC_SHADOW)) {
    5469             :                 /* Check for dynamic properties */
    5470          18 :                 if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT && Z_OBJ_HT_P(classname)->get_properties) {
    5471           4 :                         if (zend_hash_str_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name_str, name_len)) {
    5472           3 :                                 dynam_prop = 1;
    5473             :                         }
    5474             :                 }
    5475          11 :                 if (dynam_prop == 0) {
    5476           8 :                         zend_throw_exception_ex(reflection_exception_ptr, 0, "Property %s::$%s does not exist", ZSTR_VAL(ce->name), name_str);
    5477           8 :                         return;
    5478             :                 }
    5479             :         }
    5480             : 
    5481          82 :         if (dynam_prop == 0 && (property_info->flags & ZEND_ACC_PRIVATE) == 0) {
    5482             :                 /* we have to search the class hierarchy for this (implicit) public or protected property */
    5483          63 :                 zend_class_entry *tmp_ce = ce;
    5484             :                 zend_property_info *tmp_info;
    5485             : 
    5486         189 :                 while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, name_str, name_len)) == NULL) {
    5487           0 :                         ce = tmp_ce;
    5488           0 :                         property_info = tmp_info;
    5489           0 :                         tmp_ce = tmp_ce->parent;
    5490             :                 }
    5491             :         }
    5492             : 
    5493          82 :         if (dynam_prop == 0) {
    5494             :                 const char *class_name, *prop_name;
    5495             :                 size_t prop_name_len;
    5496          79 :                 zend_unmangle_property_name_ex(property_info->name, &class_name, &prop_name, &prop_name_len);
    5497          79 :                 ZVAL_STR_COPY(&cname, property_info->ce->name);
    5498         158 :                 ZVAL_STRINGL(&propname, prop_name, prop_name_len);
    5499             :         } else {
    5500           3 :                 ZVAL_STR_COPY(&cname, ce->name);
    5501           6 :                 ZVAL_STRINGL(&propname, name_str, name_len);
    5502             :         }
    5503         246 :         reflection_update_property(object, "class", &cname);
    5504         246 :         reflection_update_property(object, "name", &propname);
    5505             : 
    5506          82 :         reference = (property_reference*) emalloc(sizeof(property_reference));
    5507          82 :         if (dynam_prop) {
    5508           3 :                 reference->prop.flags = ZEND_ACC_IMPLICIT_PUBLIC;
    5509           3 :                 reference->prop.name = Z_STR(propname);
    5510           3 :                 reference->prop.doc_comment = NULL;
    5511           3 :                 reference->prop.ce = ce;
    5512             :         } else {
    5513          79 :                 reference->prop = *property_info;
    5514             :         }
    5515          82 :         reference->ce = ce;
    5516          82 :         intern->ptr = reference;
    5517          82 :         intern->ref_type = REF_TYPE_PROPERTY;
    5518          82 :         intern->ce = ce;
    5519          82 :         intern->ignore_visibility = 0;
    5520             : }
    5521             : /* }}} */
    5522             : 
    5523             : /* {{{ proto public string ReflectionProperty::__toString()
    5524             :    Returns a string representation */
    5525          13 : ZEND_METHOD(reflection_property, __toString)
    5526             : {
    5527             :         reflection_object *intern;
    5528             :         property_reference *ref;
    5529             :         string str;
    5530             : 
    5531          13 :         if (zend_parse_parameters_none() == FAILURE) {
    5532           0 :                 return;
    5533             :         }
    5534          26 :         GET_REFLECTION_OBJECT_PTR(ref);
    5535          13 :         string_init(&str);
    5536          13 :         _property_string(&str, &ref->prop, NULL, "");
    5537          13 :         RETURN_NEW_STR(str.buf);
    5538             : }
    5539             : /* }}} */
    5540             : 
    5541             : /* {{{ proto public string ReflectionProperty::getName()
    5542             :    Returns the class' name */
    5543          89 : ZEND_METHOD(reflection_property, getName)
    5544             : {
    5545          89 :         if (zend_parse_parameters_none() == FAILURE) {
    5546           1 :                 return;
    5547             :         }
    5548         176 :         _default_get_entry(getThis(), "name", sizeof("name")-1, return_value);
    5549             : }
    5550             : /* }}} */
    5551             : 
    5552         232 : static void _property_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /* {{{ */
    5553             : {
    5554             :         reflection_object *intern;
    5555             :         property_reference *ref;
    5556             : 
    5557         232 :         if (zend_parse_parameters_none() == FAILURE) {
    5558           6 :                 return;
    5559             :         }
    5560         452 :         GET_REFLECTION_OBJECT_PTR(ref);
    5561         226 :         RETURN_BOOL(ref->prop.flags & mask);
    5562             : }
    5563             : /* }}} */
    5564             : 
    5565             : /* {{{ proto public bool ReflectionProperty::isPublic()
    5566             :    Returns whether this property is public */
    5567          49 : ZEND_METHOD(reflection_property, isPublic)
    5568             : {
    5569          49 :         _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC);
    5570          49 : }
    5571             : /* }}} */
    5572             : 
    5573             : /* {{{ proto public bool ReflectionProperty::isPrivate()
    5574             :    Returns whether this property is private */
    5575          43 : ZEND_METHOD(reflection_property, isPrivate)
    5576             : {
    5577          43 :         _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PRIVATE);
    5578          43 : }
    5579             : /* }}} */
    5580             : 
    5581             : /* {{{ proto public bool ReflectionProperty::isProtected()
    5582             :    Returns whether this property is protected */
    5583          44 : ZEND_METHOD(reflection_property, isProtected)
    5584             : {
    5585          44 :         _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROTECTED);
    5586          44 : }
    5587             : /* }}} */
    5588             : 
    5589             : /* {{{ proto public bool ReflectionProperty::isStatic()
    5590             :    Returns whether this property is static */
    5591          44 : ZEND_METHOD(reflection_property, isStatic)
    5592             : {
    5593          44 :         _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_STATIC);
    5594          44 : }
    5595             : /* }}} */
    5596             : 
    5597             : /* {{{ proto public bool ReflectionProperty::isDefault()
    5598             :    Returns whether this property is default (declared at compilation time). */
    5599          52 : ZEND_METHOD(reflection_property, isDefault)
    5600             : {
    5601          52 :         _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ~ZEND_ACC_IMPLICIT_PUBLIC);
    5602          52 : }
    5603             : /* }}} */
    5604             : 
    5605             : /* {{{ proto public int ReflectionProperty::getModifiers()
    5606             :    Returns a bitfield of the access modifiers for this property */
    5607          55 : ZEND_METHOD(reflection_property, getModifiers)
    5608             : {
    5609             :         reflection_object *intern;
    5610             :         property_reference *ref;
    5611             : 
    5612          55 :         if (zend_parse_parameters_none() == FAILURE) {
    5613           1 :                 return;
    5614             :         }
    5615         108 :         GET_REFLECTION_OBJECT_PTR(ref);
    5616             : 
    5617          54 :         RETURN_LONG(ref->prop.flags);
    5618             : }
    5619             : /* }}} */
    5620             : 
    5621             : /* {{{ proto public mixed ReflectionProperty::getValue([stdclass object])
    5622             :    Returns this property's value */
    5623          79 : ZEND_METHOD(reflection_property, getValue)
    5624             : {
    5625             :         reflection_object *intern;
    5626             :         property_reference *ref;
    5627             :         zval *object, *name;
    5628          79 :         zval *member_p = NULL;
    5629             : 
    5630         158 :         METHOD_NOTSTATIC(reflection_property_ptr);
    5631         158 :         GET_REFLECTION_OBJECT_PTR(ref);
    5632             : 
    5633          79 :         if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) {
    5634          58 :                 name = _default_load_entry(getThis(), "name", sizeof("name")-1);
    5635          58 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    5636          58 :                         "Cannot access non-public member %s::%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name));
    5637          29 :                 return;
    5638             :         }
    5639             : 
    5640          50 :         if ((ref->prop.flags & ZEND_ACC_STATIC)) {
    5641          20 :                 if (UNEXPECTED(zend_update_class_constants(intern->ce) != SUCCESS)) {
    5642           0 :                         return;
    5643             :                 }
    5644          40 :                 if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) {
    5645           0 :                         zend_throw_error(NULL, "Internal error: Could not find the property %s::%s", ZSTR_VAL(intern->ce->name), ZSTR_VAL(ref->prop.name));
    5646           0 :                         return;
    5647             :                 }
    5648          20 :                 member_p = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset];
    5649          20 :                 ZVAL_DEREF(member_p);
    5650          20 :                 ZVAL_COPY(return_value, member_p);
    5651             :         } else {
    5652             :                 const char *class_name, *prop_name;
    5653             :                 size_t prop_name_len;
    5654             :                 zval rv;
    5655             : 
    5656          30 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &object) == FAILURE) {
    5657           3 :                         return;
    5658             :                 }
    5659             : 
    5660          27 :                 if (!instanceof_function(Z_OBJCE_P(object), ref->ce)) {
    5661           1 :                         _DO_THROW("Given object is not an instance of the class this property was declared in");
    5662             :                         /* Returns from this function */
    5663             :                 }
    5664             : 
    5665          26 :                 zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len);
    5666          26 :                 member_p = zend_read_property(ref->ce, object, prop_name, prop_name_len, 0, &rv);
    5667          26 :                 if (member_p != &rv) {
    5668          25 :                         ZVAL_DEREF(member_p);
    5669          25 :                         ZVAL_COPY(return_value, member_p);
    5670             :                 } else {
    5671           1 :                         if (Z_ISREF_P(member_p)) {
    5672             :                                 zend_unwrap_reference(member_p);
    5673             :                         }
    5674           1 :                         ZVAL_COPY_VALUE(return_value, member_p);
    5675             :                 }
    5676             :         }
    5677             : }
    5678             : /* }}} */
    5679             : 
    5680             : /* {{{ proto public void ReflectionProperty::setValue([stdclass object,] mixed value)
    5681             :    Sets this property's value */
    5682          27 : ZEND_METHOD(reflection_property, setValue)
    5683             : {
    5684             :         reflection_object *intern;
    5685             :         property_reference *ref;
    5686             :         zval *variable_ptr;
    5687             :         zval *object, *name;
    5688             :         zval *value;
    5689             :         zval *tmp;
    5690             : 
    5691          54 :         METHOD_NOTSTATIC(reflection_property_ptr);
    5692          54 :         GET_REFLECTION_OBJECT_PTR(ref);
    5693             : 
    5694          27 :         if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) {
    5695           2 :                 name = _default_load_entry(getThis(), "name", sizeof("name")-1);
    5696           2 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    5697           2 :                         "Cannot access non-public member %s::%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name));
    5698           1 :                 return;
    5699             :         }
    5700             : 
    5701          26 :         if ((ref->prop.flags & ZEND_ACC_STATIC)) {
    5702          12 :                 if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z", &value) == FAILURE) {
    5703           7 :                         if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &tmp, &value) == FAILURE) {
    5704           2 :                                 return;
    5705             :                         }
    5706             :                 }
    5707          10 :                 if (UNEXPECTED(zend_update_class_constants(intern->ce) != SUCCESS)) {
    5708           0 :                         return;
    5709             :                 }
    5710             : 
    5711          20 :                 if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) {
    5712           0 :                         zend_throw_error(NULL, "Internal error: Could not find the property %s::%s", ZSTR_VAL(intern->ce->name), ZSTR_VAL(ref->prop.name));
    5713           0 :                         return;
    5714             :                 }
    5715          10 :                 variable_ptr = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset];
    5716          10 :                 if (variable_ptr != value) {
    5717             :                         zval garbage;
    5718             : 
    5719          10 :                         ZVAL_DEREF(variable_ptr);
    5720          20 :                         ZVAL_DEREF(value);
    5721             : 
    5722          10 :                         ZVAL_COPY_VALUE(&garbage, variable_ptr);
    5723             : 
    5724          10 :                         ZVAL_COPY(variable_ptr, value);
    5725             : 
    5726          10 :                         zval_ptr_dtor(&garbage);
    5727             :                 }
    5728             :         } else {
    5729             :                 const char *class_name, *prop_name;
    5730             :                 size_t prop_name_len;
    5731             : 
    5732          14 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "oz", &object, &value) == FAILURE) {
    5733           4 :                         return;
    5734             :                 }
    5735             : 
    5736          10 :                 zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len);
    5737          10 :                 zend_update_property(ref->ce, object, prop_name, prop_name_len, value);
    5738             :         }
    5739             : }
    5740             : /* }}} */
    5741             : 
    5742             : /* {{{ proto public ReflectionClass ReflectionProperty::getDeclaringClass()
    5743             :    Get the declaring class */
    5744          26 : ZEND_METHOD(reflection_property, getDeclaringClass)
    5745             : {
    5746             :         reflection_object *intern;
    5747             :         property_reference *ref;
    5748             :         zend_class_entry *tmp_ce, *ce;
    5749             :         zend_property_info *tmp_info;
    5750             :         const char *prop_name, *class_name;
    5751             :         size_t prop_name_len;
    5752             : 
    5753          26 :         if (zend_parse_parameters_none() == FAILURE) {
    5754           1 :                 return;
    5755             :         }
    5756          50 :         GET_REFLECTION_OBJECT_PTR(ref);
    5757             : 
    5758          25 :         if (zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len) != SUCCESS) {
    5759           0 :                 RETURN_FALSE;
    5760             :         }
    5761             : 
    5762          25 :         ce = tmp_ce = ref->ce;
    5763          91 :         while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) != NULL) {
    5764          33 :                 if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) {
    5765             :                         /* it's a private property, so it can't be inherited */
    5766             :                         break;
    5767             :                 }
    5768          26 :                 ce = tmp_ce;
    5769          26 :                 if (tmp_ce == tmp_info->ce) {
    5770             :                         /* declared in this class, done */
    5771          18 :                         break;
    5772             :                 }
    5773           8 :                 tmp_ce = tmp_ce->parent;
    5774             :         }
    5775             : 
    5776          25 :         zend_reflection_class_factory(ce, return_value);
    5777             : }
    5778             : /* }}} */
    5779             : 
    5780             : /* {{{ proto public string ReflectionProperty::getDocComment()
    5781             :    Returns the doc comment for this property */
    5782          25 : ZEND_METHOD(reflection_property, getDocComment)
    5783             : {
    5784             :         reflection_object *intern;
    5785             :         property_reference *ref;
    5786             : 
    5787          25 :         if (zend_parse_parameters_none() == FAILURE) {
    5788           4 :                 return;
    5789             :         }
    5790          42 :         GET_REFLECTION_OBJECT_PTR(ref);
    5791          21 :         if (ref->prop.doc_comment) {
    5792          11 :                 RETURN_STR_COPY(ref->prop.doc_comment);
    5793             :         }
    5794          10 :         RETURN_FALSE;
    5795             : }
    5796             : /* }}} */
    5797             : 
    5798             : /* {{{ proto public int ReflectionProperty::setAccessible(bool visible)
    5799             :    Sets whether non-public properties can be requested */
    5800          12 : ZEND_METHOD(reflection_property, setAccessible)
    5801             : {
    5802             :         reflection_object *intern;
    5803             :         zend_bool visible;
    5804             : 
    5805          12 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &visible) == FAILURE) {
    5806           0 :                 return;
    5807             :         }
    5808             : 
    5809          24 :         intern = Z_REFLECTION_P(getThis());
    5810             : 
    5811          12 :         intern->ignore_visibility = visible;
    5812             : }
    5813             : /* }}} */
    5814             : 
    5815             : /* {{{ proto public static mixed ReflectionExtension::export(string name [, bool return]) throws ReflectionException
    5816             :    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    5817           2 : ZEND_METHOD(reflection_extension, export)
    5818             : {
    5819           2 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_extension_ptr, 1);
    5820           2 : }
    5821             : /* }}} */
    5822             : 
    5823             : /* {{{ proto public void ReflectionExtension::__construct(string name)
    5824             :    Constructor. Throws an Exception in case the given extension does not exist */
    5825          27 : ZEND_METHOD(reflection_extension, __construct)
    5826             : {
    5827             :         zval name;
    5828             :         zval *object;
    5829             :         char *lcname;
    5830             :         reflection_object *intern;
    5831             :         zend_module_entry *module;
    5832             :         char *name_str;
    5833             :         size_t name_len;
    5834             :         ALLOCA_FLAG(use_heap)
    5835             : 
    5836          27 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
    5837           3 :                 return;
    5838             :         }
    5839             : 
    5840          48 :         object = getThis();
    5841          24 :         intern = Z_REFLECTION_P(object);
    5842          24 :         lcname = do_alloca(name_len + 1, use_heap);
    5843          24 :         zend_str_tolower_copy(lcname, name_str, name_len);
    5844          48 :         if ((module = zend_hash_str_find_ptr(&module_registry, lcname, name_len)) == NULL) {
    5845           2 :                 free_alloca(lcname, use_heap);
    5846           2 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    5847             :                         "Extension %s does not exist", name_str);
    5848           2 :                 return;
    5849             :         }
    5850          22 :         free_alloca(lcname, use_heap);
    5851          44 :         ZVAL_STRING(&name, module->name);
    5852          66 :         reflection_update_property(object, "name", &name);
    5853          22 :         intern->ptr = module;
    5854          22 :         intern->ref_type = REF_TYPE_OTHER;
    5855          22 :         intern->ce = NULL;
    5856             : }
    5857             : /* }}} */
    5858             : 
    5859             : /* {{{ proto public string ReflectionExtension::__toString()
    5860             :    Returns a string representation */
    5861           3 : ZEND_METHOD(reflection_extension, __toString)
    5862             : {
    5863             :         reflection_object *intern;
    5864             :         zend_module_entry *module;
    5865             :         string str;
    5866             : 
    5867           3 :         if (zend_parse_parameters_none() == FAILURE) {
    5868           0 :                 return;
    5869             :         }
    5870           6 :         GET_REFLECTION_OBJECT_PTR(module);
    5871           3 :         string_init(&str);
    5872           3 :         _extension_string(&str, module, "");
    5873           3 :         RETURN_NEW_STR(str.buf);
    5874             : }
    5875             : /* }}} */
    5876             : 
    5877             : /* {{{ proto public string ReflectionExtension::getName()
    5878             :    Returns this extension's name */
    5879           1 : ZEND_METHOD(reflection_extension, getName)
    5880             : {
    5881           1 :         if (zend_parse_parameters_none() == FAILURE) {
    5882           0 :                 return;
    5883             :         }
    5884           2 :         _default_get_entry(getThis(), "name", sizeof("name")-1, return_value);
    5885             : }
    5886             : /* }}} */
    5887             : 
    5888             : /* {{{ proto public string ReflectionExtension::getVersion()
    5889             :    Returns this extension's version */
    5890           2 : ZEND_METHOD(reflection_extension, getVersion)
    5891             : {
    5892             :         reflection_object *intern;
    5893             :         zend_module_entry *module;
    5894             : 
    5895           2 :         if (zend_parse_parameters_none() == FAILURE) {
    5896           0 :                 return;
    5897             :         }
    5898           4 :         GET_REFLECTION_OBJECT_PTR(module);
    5899             : 
    5900             :         /* An extension does not necessarily have a version number */
    5901           2 :         if (module->version == NO_VERSION_YET) {
    5902           0 :                 RETURN_NULL();
    5903             :         } else {
    5904           4 :                 RETURN_STRING(module->version);
    5905             :         }
    5906             : }
    5907             : /* }}} */
    5908             : 
    5909             : /* {{{ proto public ReflectionFunction[] ReflectionExtension::getFunctions()
    5910             :    Returns an array of this extension's functions */
    5911           2 : ZEND_METHOD(reflection_extension, getFunctions)
    5912             : {
    5913             :         reflection_object *intern;
    5914             :         zend_module_entry *module;
    5915             :         zval function;
    5916             :         zend_function *fptr;
    5917             : 
    5918           2 :         if (zend_parse_parameters_none() == FAILURE) {
    5919           0 :                 return;
    5920             :         }
    5921           4 :         GET_REFLECTION_OBJECT_PTR(module);
    5922             : 
    5923           2 :         array_init(return_value);
    5924        8822 :         ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) {
    5925        8820 :                 if (fptr->common.type==ZEND_INTERNAL_FUNCTION
    5926        8820 :                         && fptr->internal_function.module == module) {
    5927        1060 :                         reflection_function_factory(fptr, NULL, &function);
    5928        1060 :                         zend_hash_update(Z_ARRVAL_P(return_value), fptr->common.function_name, &function);
    5929             :                 }
    5930             :         } ZEND_HASH_FOREACH_END();
    5931             : }
    5932             : /* }}} */
    5933             : 
    5934        2583 : static int _addconstant(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
    5935             : {
    5936             :         zval const_val;
    5937        2583 :         zend_constant *constant = (zend_constant*)Z_PTR_P(el);
    5938        2583 :         zval *retval = va_arg(args, zval*);
    5939        2583 :         int number = va_arg(args, int);
    5940             : 
    5941        2583 :         if (number == constant->module_number) {
    5942         363 :                 ZVAL_DUP(&const_val, &constant->value);
    5943         363 :                 zend_hash_update(Z_ARRVAL_P(retval), constant->name, &const_val);
    5944             :         }
    5945        2583 :         return 0;
    5946             : }
    5947             : /* }}} */
    5948             : 
    5949             : /* {{{ proto public array ReflectionExtension::getConstants()
    5950             :    Returns an associative array containing this extension's constants and their values */
    5951           1 : ZEND_METHOD(reflection_extension, getConstants)
    5952             : {
    5953             :         reflection_object *intern;
    5954             :         zend_module_entry *module;
    5955             : 
    5956           1 :         if (zend_parse_parameters_none() == FAILURE) {
    5957           0 :                 return;
    5958             :         }
    5959           2 :         GET_REFLECTION_OBJECT_PTR(module);
    5960             : 
    5961           1 :         array_init(return_value);
    5962           1 :         zend_hash_apply_with_arguments(EG(zend_constants), (apply_func_args_t) _addconstant, 2, return_value, module->module_number);
    5963             : }
    5964             : /* }}} */
    5965             : 
    5966             : /* {{{ _addinientry */
    5967         266 : static int _addinientry(zval *el, int num_args, va_list args, zend_hash_key *hash_key)
    5968             : {
    5969         266 :         zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el);
    5970         266 :         zval *retval = va_arg(args, zval*);
    5971         266 :         int number = va_arg(args, int);
    5972             : 
    5973         266 :         if (number == ini_entry->module_number) {
    5974          11 :                 if (ini_entry->value) {
    5975             :                         zval zv;
    5976             : 
    5977           9 :                         ZVAL_STR_COPY(&zv, ini_entry->value);
    5978           9 :                         zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &zv);
    5979             :                 } else {
    5980           2 :                         zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &EG(uninitialized_zval));
    5981             :                 }
    5982             :         }
    5983         266 :         return ZEND_HASH_APPLY_KEEP;
    5984             : }
    5985             : /* }}} */
    5986             : 
    5987             : /* {{{ proto public array ReflectionExtension::getINIEntries()
    5988             :    Returns an associative array containing this extension's INI entries and their values */
    5989           1 : ZEND_METHOD(reflection_extension, getINIEntries)
    5990             : {
    5991             :         reflection_object *intern;
    5992             :         zend_module_entry *module;
    5993             : 
    5994           1 :         if (zend_parse_parameters_none() == FAILURE) {
    5995           0 :                 return;
    5996             :         }
    5997           2 :         GET_REFLECTION_OBJECT_PTR(module);
    5998             : 
    5999           1 :         array_init(return_value);
    6000           1 :         zend_hash_apply_with_arguments(EG(ini_directives), (apply_func_args_t) _addinientry, 2, return_value, module->module_number);
    6001             : }
    6002             : /* }}} */
    6003             : 
    6004             : /* {{{ add_extension_class */
    6005         772 : static int add_extension_class(zval *zv, int num_args, va_list args, zend_hash_key *hash_key)
    6006             : {
    6007         772 :         zend_class_entry *ce = Z_PTR_P(zv);
    6008         772 :         zval *class_array = va_arg(args, zval*), zclass;
    6009         772 :         struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*);
    6010         772 :         int add_reflection_class = va_arg(args, int);
    6011             : 
    6012         772 :         if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) {
    6013             :                 zend_string *name;
    6014             : 
    6015          34 :                 if (zend_binary_strcasecmp(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key))) {
    6016             :                         /* This is an class alias, use alias name */
    6017           0 :                         name = hash_key->key;
    6018             :                 } else {
    6019             :                         /* Use class name */
    6020          34 :                         name = ce->name;
    6021             :                 }
    6022          34 :                 if (add_reflection_class) {
    6023          30 :                         zend_reflection_class_factory(ce, &zclass);
    6024          30 :                         zend_hash_update(Z_ARRVAL_P(class_array), name, &zclass);
    6025             :                 } else {
    6026           4 :                         add_next_index_str(class_array, zend_string_copy(name));
    6027             :                 }
    6028             :         }
    6029         772 :         return ZEND_HASH_APPLY_KEEP;
    6030             : }
    6031             : /* }}} */
    6032             : 
    6033             : /* {{{ proto public ReflectionClass[] ReflectionExtension::getClasses()
    6034             :    Returns an array containing ReflectionClass objects for all classes of this extension */
    6035           2 : ZEND_METHOD(reflection_extension, getClasses)
    6036             : {
    6037             :         reflection_object *intern;
    6038             :         zend_module_entry *module;
    6039             : 
    6040           2 :         if (zend_parse_parameters_none() == FAILURE) {
    6041           0 :                 return;
    6042             :         }
    6043           4 :         GET_REFLECTION_OBJECT_PTR(module);
    6044             : 
    6045           2 :         array_init(return_value);
    6046           2 :         zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) add_extension_class, 3, return_value, module, 1);
    6047             : }
    6048             : /* }}} */
    6049             : 
    6050             : /* {{{ proto public array ReflectionExtension::getClassNames()
    6051             :    Returns an array containing all names of all classes of this extension */
    6052           2 : ZEND_METHOD(reflection_extension, getClassNames)
    6053             : {
    6054             :         reflection_object *intern;
    6055             :         zend_module_entry *module;
    6056             : 
    6057           2 :         if (zend_parse_parameters_none() == FAILURE) {
    6058           0 :                 return;
    6059             :         }
    6060           4 :         GET_REFLECTION_OBJECT_PTR(module);
    6061             : 
    6062           2 :         array_init(return_value);
    6063           2 :         zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) add_extension_class, 3, return_value, module, 0);
    6064             : }
    6065             : /* }}} */
    6066             : 
    6067             : /* {{{ proto public array ReflectionExtension::getDependencies()
    6068             :    Returns an array containing all names of all extensions this extension depends on */
    6069           3 : ZEND_METHOD(reflection_extension, getDependencies)
    6070             : {
    6071             :         reflection_object *intern;
    6072             :         zend_module_entry *module;
    6073             :         const zend_module_dep *dep;
    6074             : 
    6075           3 :         if (zend_parse_parameters_none() == FAILURE) {
    6076           0 :                 return;
    6077             :         }
    6078           6 :         GET_REFLECTION_OBJECT_PTR(module);
    6079             : 
    6080           3 :         array_init(return_value);
    6081             : 
    6082           3 :         dep = module->deps;
    6083             : 
    6084           3 :         if (!dep)
    6085             :         {
    6086           0 :                 return;
    6087             :         }
    6088             : 
    6089          10 :         while(dep->name) {
    6090             :                 zend_string *relation;
    6091             :                 char *rel_type;
    6092           4 :                 size_t len = 0;
    6093             : 
    6094           4 :                 switch(dep->type) {
    6095             :                         case MODULE_DEP_REQUIRED:
    6096           2 :                                 rel_type = "Required";
    6097           2 :                                 len += sizeof("Required") - 1;
    6098           2 :                                 break;
    6099             :                         case MODULE_DEP_CONFLICTS:
    6100           1 :                                 rel_type = "Conflicts";
    6101           1 :                                 len += sizeof("Conflicts") - 1;
    6102           1 :                                 break;
    6103             :                         case MODULE_DEP_OPTIONAL:
    6104           1 :                                 rel_type = "Optional";
    6105           1 :                                 len += sizeof("Optional") - 1;
    6106           1 :                                 break;
    6107             :                         default:
    6108           0 :                                 rel_type = "Error"; /* shouldn't happen */
    6109           0 :                                 len += sizeof("Error") - 1;
    6110             :                                 break;
    6111             :                 }
    6112             : 
    6113           4 :                 if (dep->rel) {
    6114           0 :                         len += strlen(dep->rel) + 1;
    6115             :                 }
    6116             : 
    6117           4 :                 if (dep->version) {
    6118           0 :                         len += strlen(dep->version) + 1;
    6119             :                 }
    6120             : 
    6121           4 :                 relation = zend_string_alloc(len, 0);
    6122          16 :                 snprintf(ZSTR_VAL(relation), ZSTR_LEN(relation) + 1, "%s%s%s%s%s",
    6123             :                                                 rel_type,
    6124           4 :                                                 dep->rel ? " " : "",
    6125           4 :                                                 dep->rel ? dep->rel : "",
    6126           4 :                                                 dep->version ? " " : "",
    6127           4 :                                                 dep->version ? dep->version : "");
    6128           4 :                 add_assoc_str(return_value, dep->name, relation);
    6129           4 :                 dep++;
    6130             :         }
    6131             : }
    6132             : /* }}} */
    6133             : 
    6134             : /* {{{ proto public void ReflectionExtension::info()
    6135             :        Prints phpinfo block for the extension */
    6136           3 : ZEND_METHOD(reflection_extension, info)
    6137             : {
    6138             :         reflection_object *intern;
    6139             :         zend_module_entry *module;
    6140             : 
    6141           3 :         if (zend_parse_parameters_none() == FAILURE) {
    6142           0 :                 return;
    6143             :         }
    6144           6 :         GET_REFLECTION_OBJECT_PTR(module);
    6145             : 
    6146           3 :         php_info_print_module(module);
    6147             : }
    6148             : /* }}} */
    6149             : 
    6150             : /* {{{ proto public bool ReflectionExtension::isPersistent()
    6151             :        Returns whether this extension is persistent */
    6152           1 : ZEND_METHOD(reflection_extension, isPersistent)
    6153             : {
    6154             :         reflection_object *intern;
    6155             :     zend_module_entry *module;
    6156             : 
    6157           1 :     if (zend_parse_parameters_none() == FAILURE) {
    6158           0 :                 return;
    6159             :         }
    6160           2 :         GET_REFLECTION_OBJECT_PTR(module);
    6161             : 
    6162           1 :         RETURN_BOOL(module->type == MODULE_PERSISTENT);
    6163             : }
    6164             : /* }}} */
    6165             : 
    6166             : /* {{{ proto public bool ReflectionExtension::isTemporary()
    6167             :        Returns whether this extension is temporary */
    6168           1 : ZEND_METHOD(reflection_extension, isTemporary)
    6169             : {
    6170             :         reflection_object *intern;
    6171             :         zend_module_entry *module;
    6172             : 
    6173           1 :         if (zend_parse_parameters_none() == FAILURE) {
    6174           0 :                 return;
    6175             :         }
    6176           2 :         GET_REFLECTION_OBJECT_PTR(module);
    6177             : 
    6178           1 :         RETURN_BOOL(module->type == MODULE_TEMPORARY);
    6179             : }
    6180             : /* }}} */
    6181             : 
    6182             : /* {{{ proto public static mixed ReflectionZendExtension::export(string name [, bool return]) throws ReflectionException
    6183             :  *    Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
    6184           0 : ZEND_METHOD(reflection_zend_extension, export)
    6185             : {
    6186           0 :         _reflection_export(INTERNAL_FUNCTION_PARAM_PASSTHRU, reflection_zend_extension_ptr, 1);
    6187           0 : }
    6188             : /* }}} */
    6189             : 
    6190             : /* {{{ proto public void ReflectionZendExtension::__construct(string name)
    6191             :        Constructor. Throws an Exception in case the given Zend extension does not exist */
    6192           0 : ZEND_METHOD(reflection_zend_extension, __construct)
    6193             : {
    6194             :         zval name;
    6195             :         zval *object;
    6196             :         reflection_object *intern;
    6197             :         zend_extension *extension;
    6198             :         char *name_str;
    6199             :         size_t name_len;
    6200             : 
    6201           0 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
    6202           0 :                 return;
    6203             :         }
    6204             : 
    6205           0 :         object = getThis();
    6206           0 :         intern = Z_REFLECTION_P(object);
    6207             : 
    6208           0 :         extension = zend_get_extension(name_str);
    6209           0 :         if (!extension) {
    6210           0 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    6211             :                                 "Zend Extension %s does not exist", name_str);
    6212           0 :                 return;
    6213             :         }
    6214           0 :         ZVAL_STRING(&name, extension->name);
    6215           0 :         reflection_update_property(object, "name", &name);
    6216           0 :         intern->ptr = extension;
    6217           0 :         intern->ref_type = REF_TYPE_OTHER;
    6218           0 :         intern->ce = NULL;
    6219             : }
    6220             : /* }}} */
    6221             : 
    6222             : /* {{{ proto public string ReflectionZendExtension::__toString()
    6223             :        Returns a string representation */
    6224           0 : ZEND_METHOD(reflection_zend_extension, __toString)
    6225             : {
    6226             :         reflection_object *intern;
    6227             :         zend_extension *extension;
    6228             :         string str;
    6229             : 
    6230           0 :         if (zend_parse_parameters_none() == FAILURE) {
    6231           0 :                 return;
    6232             :         }
    6233           0 :         GET_REFLECTION_OBJECT_PTR(extension);
    6234           0 :         string_init(&str);
    6235           0 :         _zend_extension_string(&str, extension, "");
    6236           0 :         RETURN_NEW_STR(str.buf);
    6237             : }
    6238             : /* }}} */
    6239             : 
    6240             : /* {{{ proto public string ReflectionZendExtension::getName()
    6241             :        Returns the name of this Zend extension */
    6242           0 : ZEND_METHOD(reflection_zend_extension, getName)
    6243             : {
    6244             :         reflection_object *intern;
    6245             :         zend_extension *extension;
    6246             : 
    6247           0 :         if (zend_parse_parameters_none() == FAILURE) {
    6248           0 :                 return;
    6249             :         }
    6250           0 :         GET_REFLECTION_OBJECT_PTR(extension);
    6251             : 
    6252           0 :         RETURN_STRING(extension->name);
    6253             : }
    6254             : /* }}} */
    6255             : 
    6256             : /* {{{ proto public string ReflectionZendExtension::getVersion()
    6257             :        Returns the version information of this Zend extension */
    6258           0 : ZEND_METHOD(reflection_zend_extension, getVersion)
    6259             : {
    6260             :         reflection_object *intern;
    6261             :         zend_extension *extension;
    6262             : 
    6263           0 :         if (zend_parse_parameters_none() == FAILURE) {
    6264           0 :                 return;
    6265             :         }
    6266           0 :         GET_REFLECTION_OBJECT_PTR(extension);
    6267             : 
    6268           0 :         if (extension->version) {
    6269           0 :                 RETURN_STRING(extension->version);
    6270             :         } else {
    6271           0 :                 RETURN_EMPTY_STRING();
    6272             :         }
    6273             : }
    6274             : /* }}} */
    6275             : 
    6276             : /* {{{ proto public void ReflectionZendExtension::getAuthor()
    6277             :  * Returns the name of this Zend extension's author */
    6278           0 : ZEND_METHOD(reflection_zend_extension, getAuthor)
    6279             : {
    6280             :         reflection_object *intern;
    6281             :         zend_extension *extension;
    6282             : 
    6283           0 :         if (zend_parse_parameters_none() == FAILURE) {
    6284           0 :                 return;
    6285             :         }
    6286           0 :         GET_REFLECTION_OBJECT_PTR(extension);
    6287             : 
    6288           0 :         if (extension->author) {
    6289           0 :                 RETURN_STRING(extension->author);
    6290             :         } else {
    6291           0 :                 RETURN_EMPTY_STRING();
    6292             :         }
    6293             : }
    6294             : /* }}} */
    6295             : 
    6296             : /* {{{ proto public void ReflectionZendExtension::getURL()
    6297             :        Returns this Zend extension's URL*/
    6298           0 : ZEND_METHOD(reflection_zend_extension, getURL)
    6299             : {
    6300             :         reflection_object *intern;
    6301             :         zend_extension *extension;
    6302             : 
    6303           0 :         if (zend_parse_parameters_none() == FAILURE) {
    6304           0 :                 return;
    6305             :         }
    6306           0 :         GET_REFLECTION_OBJECT_PTR(extension);
    6307             : 
    6308           0 :         if (extension->URL) {
    6309           0 :                 RETURN_STRING(extension->URL);
    6310             :         } else {
    6311           0 :                 RETURN_EMPTY_STRING();
    6312             :         }
    6313             : }
    6314             : /* }}} */
    6315             : 
    6316             : /* {{{ proto public void ReflectionZendExtension::getCopyright()
    6317             :        Returns this Zend extension's copyright information */
    6318           0 : ZEND_METHOD(reflection_zend_extension, getCopyright)
    6319             : {
    6320             :         reflection_object *intern;
    6321             :         zend_extension *extension;
    6322             : 
    6323           0 :         if (zend_parse_parameters_none() == FAILURE) {
    6324           0 :                 return;
    6325             :         }
    6326           0 :         GET_REFLECTION_OBJECT_PTR(extension);
    6327             : 
    6328           0 :         if (extension->copyright) {
    6329           0 :                 RETURN_STRING(extension->copyright);
    6330             :         } else {
    6331           0 :                 RETURN_EMPTY_STRING();
    6332             :         }
    6333             : }
    6334             : /* }}} */
    6335             : 
    6336             : /* {{{ method tables */
    6337             : static const zend_function_entry reflection_exception_functions[] = {
    6338             :         PHP_FE_END
    6339             : };
    6340             : 
    6341             : ZEND_BEGIN_ARG_INFO(arginfo_reflection__void, 0)
    6342             : ZEND_END_ARG_INFO()
    6343             : 
    6344             : 
    6345             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_getModifierNames, 0)
    6346             :         ZEND_ARG_INFO(0, modifiers)
    6347             : ZEND_END_ARG_INFO()
    6348             : 
    6349             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_export, 0, 0, 1)
    6350             :         ZEND_ARG_OBJ_INFO(0, reflector, Reflector, 0)
    6351             :         ZEND_ARG_INFO(0, return)
    6352             : ZEND_END_ARG_INFO()
    6353             : 
    6354             : static const zend_function_entry reflection_functions[] = {
    6355             :         ZEND_ME(reflection, getModifierNames, arginfo_reflection_getModifierNames, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
    6356             :         ZEND_ME(reflection, export, arginfo_reflection_export, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
    6357             :         PHP_FE_END
    6358             : };
    6359             : 
    6360             : static const zend_function_entry reflector_functions[] = {
    6361             :         ZEND_FENTRY(export, NULL, NULL, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)
    6362             :         ZEND_ABSTRACT_ME(reflector, __toString, arginfo_reflection__void)
    6363             :         PHP_FE_END
    6364             : };
    6365             : 
    6366             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_function_export, 0, 0, 1)
    6367             :         ZEND_ARG_INFO(0, name)
    6368             :         ZEND_ARG_INFO(0, return)
    6369             : ZEND_END_ARG_INFO()
    6370             : 
    6371             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_function___construct, 0)
    6372             :         ZEND_ARG_INFO(0, name)
    6373             : ZEND_END_ARG_INFO()
    6374             : 
    6375             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_function_invoke, 0, 0, 0)
    6376             :         ZEND_ARG_INFO(0, args)
    6377             : ZEND_END_ARG_INFO()
    6378             : 
    6379             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_function_invokeArgs, 0)
    6380             :         ZEND_ARG_ARRAY_INFO(0, args, 0)
    6381             : ZEND_END_ARG_INFO()
    6382             : 
    6383             : static const zend_function_entry reflection_function_abstract_functions[] = {
    6384             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6385             :         ZEND_ME(reflection_function, inNamespace, arginfo_reflection__void, 0)
    6386             :         ZEND_ME(reflection_function, isClosure, arginfo_reflection__void, 0)
    6387             :         ZEND_ME(reflection_function, isDeprecated, arginfo_reflection__void, 0)
    6388             :         ZEND_ME(reflection_function, isInternal, arginfo_reflection__void, 0)
    6389             :         ZEND_ME(reflection_function, isUserDefined, arginfo_reflection__void, 0)
    6390             :         ZEND_ME(reflection_function, isGenerator, arginfo_reflection__void, 0)
    6391             :         ZEND_ME(reflection_function, isVariadic, arginfo_reflection__void, 0)
    6392             :         ZEND_ME(reflection_function, getClosureThis, arginfo_reflection__void, 0)
    6393             :         ZEND_ME(reflection_function, getClosureScopeClass, arginfo_reflection__void, 0)
    6394             :         ZEND_ME(reflection_function, getDocComment, arginfo_reflection__void, 0)
    6395             :         ZEND_ME(reflection_function, getEndLine, arginfo_reflection__void, 0)
    6396             :         ZEND_ME(reflection_function, getExtension, arginfo_reflection__void, 0)
    6397             :         ZEND_ME(reflection_function, getExtensionName, arginfo_reflection__void, 0)
    6398             :         ZEND_ME(reflection_function, getFileName, arginfo_reflection__void, 0)
    6399             :         ZEND_ME(reflection_function, getName, arginfo_reflection__void, 0)
    6400             :         ZEND_ME(reflection_function, getNamespaceName, arginfo_reflection__void, 0)
    6401             :         ZEND_ME(reflection_function, getNumberOfParameters, arginfo_reflection__void, 0)
    6402             :         ZEND_ME(reflection_function, getNumberOfRequiredParameters, arginfo_reflection__void, 0)
    6403             :         ZEND_ME(reflection_function, getParameters, arginfo_reflection__void, 0)
    6404             :         ZEND_ME(reflection_function, getShortName, arginfo_reflection__void, 0)
    6405             :         ZEND_ME(reflection_function, getStartLine, arginfo_reflection__void, 0)
    6406             :         ZEND_ME(reflection_function, getStaticVariables, arginfo_reflection__void, 0)
    6407             :         ZEND_ME(reflection_function, returnsReference, arginfo_reflection__void, 0)
    6408             :         ZEND_ME(reflection_function, hasReturnType, arginfo_reflection__void, 0)
    6409             :         ZEND_ME(reflection_function, getReturnType, arginfo_reflection__void, 0)
    6410             :         PHP_FE_END
    6411             : };
    6412             : 
    6413             : static const zend_function_entry reflection_function_functions[] = {
    6414             :         ZEND_ME(reflection_function, __construct, arginfo_reflection_function___construct, 0)
    6415             :         ZEND_ME(reflection_function, __toString, arginfo_reflection__void, 0)
    6416             :         ZEND_ME(reflection_function, export, arginfo_reflection_function_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6417             :         ZEND_ME(reflection_function, isDisabled, arginfo_reflection__void, 0)
    6418             :         ZEND_ME(reflection_function, invoke, arginfo_reflection_function_invoke, 0)
    6419             :         ZEND_ME(reflection_function, invokeArgs, arginfo_reflection_function_invokeArgs, 0)
    6420             :         ZEND_ME(reflection_function, getClosure, arginfo_reflection__void, 0)
    6421             :         PHP_FE_END
    6422             : };
    6423             : 
    6424             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_generator___construct, 0)
    6425             :         ZEND_ARG_INFO(0, generator)
    6426             : ZEND_END_ARG_INFO()
    6427             : 
    6428             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_generator_trace, 0, 0, 0)
    6429             :         ZEND_ARG_INFO(0, options)
    6430             : ZEND_END_ARG_INFO()
    6431             : 
    6432             : static const zend_function_entry reflection_generator_functions[] = {
    6433             :         ZEND_ME(reflection_generator, __construct, arginfo_reflection_generator___construct, 0)
    6434             :         ZEND_ME(reflection_generator, getExecutingLine, arginfo_reflection__void, 0)
    6435             :         ZEND_ME(reflection_generator, getExecutingFile, arginfo_reflection__void, 0)
    6436             :         ZEND_ME(reflection_generator, getTrace, arginfo_reflection_generator_trace, 0)
    6437             :         ZEND_ME(reflection_generator, getFunction, arginfo_reflection__void, 0)
    6438             :         ZEND_ME(reflection_generator, getThis, arginfo_reflection__void, 0)
    6439             :         ZEND_ME(reflection_generator, getExecutingGenerator, arginfo_reflection__void, 0)
    6440             :         PHP_FE_END
    6441             : };
    6442             : 
    6443             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_method_export, 0, 0, 2)
    6444             :         ZEND_ARG_INFO(0, class)
    6445             :         ZEND_ARG_INFO(0, name)
    6446             :         ZEND_ARG_INFO(0, return)
    6447             : ZEND_END_ARG_INFO()
    6448             : 
    6449             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_method___construct, 0, 0, 1)
    6450             :         ZEND_ARG_INFO(0, class_or_method)
    6451             :         ZEND_ARG_INFO(0, name)
    6452             : ZEND_END_ARG_INFO()
    6453             : 
    6454             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_invoke, 0)
    6455             :         ZEND_ARG_INFO(0, object)
    6456             :         ZEND_ARG_INFO(0, args)
    6457             : ZEND_END_ARG_INFO()
    6458             : 
    6459             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_invokeArgs, 0)
    6460             :         ZEND_ARG_INFO(0, object)
    6461             :         ZEND_ARG_ARRAY_INFO(0, args, 0)
    6462             : ZEND_END_ARG_INFO()
    6463             : 
    6464             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_setAccessible, 0)
    6465             :         ZEND_ARG_INFO(0, value)
    6466             : ZEND_END_ARG_INFO()
    6467             : 
    6468             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_getClosure, 0)
    6469             :         ZEND_ARG_INFO(0, object)
    6470             : ZEND_END_ARG_INFO()
    6471             : 
    6472             : static const zend_function_entry reflection_method_functions[] = {
    6473             :         ZEND_ME(reflection_method, export, arginfo_reflection_method_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6474             :         ZEND_ME(reflection_method, __construct, arginfo_reflection_method___construct, 0)
    6475             :         ZEND_ME(reflection_method, __toString, arginfo_reflection__void, 0)
    6476             :         ZEND_ME(reflection_method, isPublic, arginfo_reflection__void, 0)
    6477             :         ZEND_ME(reflection_method, isPrivate, arginfo_reflection__void, 0)
    6478             :         ZEND_ME(reflection_method, isProtected, arginfo_reflection__void, 0)
    6479             :         ZEND_ME(reflection_method, isAbstract, arginfo_reflection__void, 0)
    6480             :         ZEND_ME(reflection_method, isFinal, arginfo_reflection__void, 0)
    6481             :         ZEND_ME(reflection_method, isStatic, arginfo_reflection__void, 0)
    6482             :         ZEND_ME(reflection_method, isConstructor, arginfo_reflection__void, 0)
    6483             :         ZEND_ME(reflection_method, isDestructor, arginfo_reflection__void, 0)
    6484             :         ZEND_ME(reflection_method, getClosure, arginfo_reflection_method_getClosure, 0)
    6485             :         ZEND_ME(reflection_method, getModifiers, arginfo_reflection__void, 0)
    6486             :         ZEND_ME(reflection_method, invoke, arginfo_reflection_method_invoke, 0)
    6487             :         ZEND_ME(reflection_method, invokeArgs, arginfo_reflection_method_invokeArgs, 0)
    6488             :         ZEND_ME(reflection_method, getDeclaringClass, arginfo_reflection__void, 0)
    6489             :         ZEND_ME(reflection_method, getPrototype, arginfo_reflection__void, 0)
    6490             :         ZEND_ME(reflection_method, setAccessible, arginfo_reflection_method_setAccessible, 0)
    6491             :         PHP_FE_END
    6492             : };
    6493             : 
    6494             : 
    6495             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_export, 0, 0, 1)
    6496             :         ZEND_ARG_INFO(0, argument)
    6497             :         ZEND_ARG_INFO(0, return)
    6498             : ZEND_END_ARG_INFO()
    6499             : 
    6500             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class___construct, 0)
    6501             :         ZEND_ARG_INFO(0, argument)
    6502             : ZEND_END_ARG_INFO()
    6503             : 
    6504             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_getStaticPropertyValue, 0, 0, 1)
    6505             :         ZEND_ARG_INFO(0, name)
    6506             :         ZEND_ARG_INFO(0, default)
    6507             : ZEND_END_ARG_INFO()
    6508             : 
    6509             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_setStaticPropertyValue, 0)
    6510             :         ZEND_ARG_INFO(0, name)
    6511             :         ZEND_ARG_INFO(0, value)
    6512             : ZEND_END_ARG_INFO()
    6513             : 
    6514             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_hasMethod, 0)
    6515             :         ZEND_ARG_INFO(0, name)
    6516             : ZEND_END_ARG_INFO()
    6517             : 
    6518             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_getMethod, 0)
    6519             :         ZEND_ARG_INFO(0, name)
    6520             : ZEND_END_ARG_INFO()
    6521             : 
    6522             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_getMethods, 0, 0, 0)
    6523             :         ZEND_ARG_INFO(0, filter)
    6524             : ZEND_END_ARG_INFO()
    6525             : 
    6526             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_hasProperty, 0)
    6527             :         ZEND_ARG_INFO(0, name)
    6528             : ZEND_END_ARG_INFO()
    6529             : 
    6530             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_getProperty, 0)
    6531             :         ZEND_ARG_INFO(0, name)
    6532             : ZEND_END_ARG_INFO()
    6533             : 
    6534             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_getProperties, 0, 0, 0)
    6535             :         ZEND_ARG_INFO(0, filter)
    6536             : ZEND_END_ARG_INFO()
    6537             : 
    6538             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_hasConstant, 0)
    6539             :         ZEND_ARG_INFO(0, name)
    6540             : ZEND_END_ARG_INFO()
    6541             : 
    6542             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_getConstant, 0)
    6543             :         ZEND_ARG_INFO(0, name)
    6544             : ZEND_END_ARG_INFO()
    6545             : 
    6546             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_isInstance, 0)
    6547             :         ZEND_ARG_INFO(0, object)
    6548             : ZEND_END_ARG_INFO()
    6549             : 
    6550             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_newInstance, 0)
    6551             :         ZEND_ARG_INFO(0, args)
    6552             : ZEND_END_ARG_INFO()
    6553             : 
    6554             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_newInstanceWithoutConstructor, 0)
    6555             : ZEND_END_ARG_INFO()
    6556             : 
    6557             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_newInstanceArgs, 0, 0, 0)
    6558             :         ZEND_ARG_ARRAY_INFO(0, args, 0)
    6559             : ZEND_END_ARG_INFO()
    6560             : 
    6561             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_isSubclassOf, 0)
    6562             :         ZEND_ARG_INFO(0, class)
    6563             : ZEND_END_ARG_INFO()
    6564             : 
    6565             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_implementsInterface, 0)
    6566             :         ZEND_ARG_INFO(0, interface)
    6567             : ZEND_END_ARG_INFO()
    6568             : 
    6569             : static const zend_function_entry reflection_class_functions[] = {
    6570             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6571             :         ZEND_ME(reflection_class, export, arginfo_reflection_class_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6572             :         ZEND_ME(reflection_class, __construct, arginfo_reflection_class___construct, 0)
    6573             :         ZEND_ME(reflection_class, __toString, arginfo_reflection__void, 0)
    6574             :         ZEND_ME(reflection_class, getName, arginfo_reflection__void, 0)
    6575             :         ZEND_ME(reflection_class, isInternal, arginfo_reflection__void, 0)
    6576             :         ZEND_ME(reflection_class, isUserDefined, arginfo_reflection__void, 0)
    6577             :         ZEND_ME(reflection_class, isAnonymous, arginfo_reflection__void, 0)
    6578             :         ZEND_ME(reflection_class, isInstantiable, arginfo_reflection__void, 0)
    6579             :         ZEND_ME(reflection_class, isCloneable, arginfo_reflection__void, 0)
    6580             :         ZEND_ME(reflection_class, getFileName, arginfo_reflection__void, 0)
    6581             :         ZEND_ME(reflection_class, getStartLine, arginfo_reflection__void, 0)
    6582             :         ZEND_ME(reflection_class, getEndLine, arginfo_reflection__void, 0)
    6583             :         ZEND_ME(reflection_class, getDocComment, arginfo_reflection__void, 0)
    6584             :         ZEND_ME(reflection_class, getConstructor, arginfo_reflection__void, 0)
    6585             :         ZEND_ME(reflection_class, hasMethod, arginfo_reflection_class_hasMethod, 0)
    6586             :         ZEND_ME(reflection_class, getMethod, arginfo_reflection_class_getMethod, 0)
    6587             :         ZEND_ME(reflection_class, getMethods, arginfo_reflection_class_getMethods, 0)
    6588             :         ZEND_ME(reflection_class, hasProperty, arginfo_reflection_class_hasProperty, 0)
    6589             :         ZEND_ME(reflection_class, getProperty, arginfo_reflection_class_getProperty, 0)
    6590             :         ZEND_ME(reflection_class, getProperties, arginfo_reflection_class_getProperties, 0)
    6591             :         ZEND_ME(reflection_class, hasConstant, arginfo_reflection_class_hasConstant, 0)
    6592             :         ZEND_ME(reflection_class, getConstants, arginfo_reflection__void, 0)
    6593             :         ZEND_ME(reflection_class, getReflectionConstants, arginfo_reflection__void, 0)
    6594             :         ZEND_ME(reflection_class, getConstant, arginfo_reflection_class_getConstant, 0)
    6595             :         ZEND_ME(reflection_class, getReflectionConstant, arginfo_reflection_class_getConstant, 0)
    6596             :         ZEND_ME(reflection_class, getInterfaces, arginfo_reflection__void, 0)
    6597             :         ZEND_ME(reflection_class, getInterfaceNames, arginfo_reflection__void, 0)
    6598             :         ZEND_ME(reflection_class, isInterface, arginfo_reflection__void, 0)
    6599             :         ZEND_ME(reflection_class, getTraits, arginfo_reflection__void, 0)
    6600             :         ZEND_ME(reflection_class, getTraitNames, arginfo_reflection__void, 0)
    6601             :         ZEND_ME(reflection_class, getTraitAliases, arginfo_reflection__void, 0)
    6602             :         ZEND_ME(reflection_class, isTrait, arginfo_reflection__void, 0)
    6603             :         ZEND_ME(reflection_class, isAbstract, arginfo_reflection__void, 0)
    6604             :         ZEND_ME(reflection_class, isFinal, arginfo_reflection__void, 0)
    6605             :         ZEND_ME(reflection_class, getModifiers, arginfo_reflection__void, 0)
    6606             :         ZEND_ME(reflection_class, isInstance, arginfo_reflection_class_isInstance, 0)
    6607             :         ZEND_ME(reflection_class, newInstance, arginfo_reflection_class_newInstance, 0)
    6608             :         ZEND_ME(reflection_class, newInstanceWithoutConstructor, arginfo_reflection_class_newInstanceWithoutConstructor, 0)
    6609             :         ZEND_ME(reflection_class, newInstanceArgs, arginfo_reflection_class_newInstanceArgs, 0)
    6610             :         ZEND_ME(reflection_class, getParentClass, arginfo_reflection__void, 0)
    6611             :         ZEND_ME(reflection_class, isSubclassOf, arginfo_reflection_class_isSubclassOf, 0)
    6612             :         ZEND_ME(reflection_class, getStaticProperties, arginfo_reflection__void, 0)
    6613             :         ZEND_ME(reflection_class, getStaticPropertyValue, arginfo_reflection_class_getStaticPropertyValue, 0)
    6614             :         ZEND_ME(reflection_class, setStaticPropertyValue, arginfo_reflection_class_setStaticPropertyValue, 0)
    6615             :         ZEND_ME(reflection_class, getDefaultProperties, arginfo_reflection__void, 0)
    6616             :         ZEND_ME(reflection_class, isIterateable, arginfo_reflection__void, 0)
    6617             :         ZEND_ME(reflection_class, implementsInterface, arginfo_reflection_class_implementsInterface, 0)
    6618             :         ZEND_ME(reflection_class, getExtension, arginfo_reflection__void, 0)
    6619             :         ZEND_ME(reflection_class, getExtensionName, arginfo_reflection__void, 0)
    6620             :         ZEND_ME(reflection_class, inNamespace, arginfo_reflection__void, 0)
    6621             :         ZEND_ME(reflection_class, getNamespaceName, arginfo_reflection__void, 0)
    6622             :         ZEND_ME(reflection_class, getShortName, arginfo_reflection__void, 0)
    6623             :         PHP_FE_END
    6624             : };
    6625             : 
    6626             : 
    6627             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_object_export, 0, 0, 1)
    6628             :         ZEND_ARG_INFO(0, argument)
    6629             :         ZEND_ARG_INFO(0, return)
    6630             : ZEND_END_ARG_INFO()
    6631             : 
    6632             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_object___construct, 0)
    6633             :         ZEND_ARG_INFO(0, argument)
    6634             : ZEND_END_ARG_INFO()
    6635             : 
    6636             : static const zend_function_entry reflection_object_functions[] = {
    6637             :         ZEND_ME(reflection_object, export, arginfo_reflection_object_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6638             :         ZEND_ME(reflection_object, __construct, arginfo_reflection_object___construct, 0)
    6639             :         PHP_FE_END
    6640             : };
    6641             : 
    6642             : 
    6643             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property_export, 0, 0, 2)
    6644             :         ZEND_ARG_INFO(0, class)
    6645             :         ZEND_ARG_INFO(0, name)
    6646             :         ZEND_ARG_INFO(0, return)
    6647             : ZEND_END_ARG_INFO()
    6648             : 
    6649             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property___construct, 0, 0, 2)
    6650             :         ZEND_ARG_INFO(0, class)
    6651             :         ZEND_ARG_INFO(0, name)
    6652             : ZEND_END_ARG_INFO()
    6653             : 
    6654             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property_getValue, 0, 0, 0)
    6655             :         ZEND_ARG_INFO(0, object)
    6656             : ZEND_END_ARG_INFO()
    6657             : 
    6658             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_property_setValue, 0, 0, 1)
    6659             :         ZEND_ARG_INFO(0, object)
    6660             :         ZEND_ARG_INFO(0, value)
    6661             : ZEND_END_ARG_INFO()
    6662             : 
    6663             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_property_setAccessible, 0)
    6664             :         ZEND_ARG_INFO(0, visible)
    6665             : ZEND_END_ARG_INFO()
    6666             : 
    6667             : static const zend_function_entry reflection_property_functions[] = {
    6668             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6669             :         ZEND_ME(reflection_property, export, arginfo_reflection_property_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6670             :         ZEND_ME(reflection_property, __construct, arginfo_reflection_property___construct, 0)
    6671             :         ZEND_ME(reflection_property, __toString, arginfo_reflection__void, 0)
    6672             :         ZEND_ME(reflection_property, getName, arginfo_reflection__void, 0)
    6673             :         ZEND_ME(reflection_property, getValue, arginfo_reflection_property_getValue, 0)
    6674             :         ZEND_ME(reflection_property, setValue, arginfo_reflection_property_setValue, 0)
    6675             :         ZEND_ME(reflection_property, isPublic, arginfo_reflection__void, 0)
    6676             :         ZEND_ME(reflection_property, isPrivate, arginfo_reflection__void, 0)
    6677             :         ZEND_ME(reflection_property, isProtected, arginfo_reflection__void, 0)
    6678             :         ZEND_ME(reflection_property, isStatic, arginfo_reflection__void, 0)
    6679             :         ZEND_ME(reflection_property, isDefault, arginfo_reflection__void, 0)
    6680             :         ZEND_ME(reflection_property, getModifiers, arginfo_reflection__void, 0)
    6681             :         ZEND_ME(reflection_property, getDeclaringClass, arginfo_reflection__void, 0)
    6682             :         ZEND_ME(reflection_property, getDocComment, arginfo_reflection__void, 0)
    6683             :         ZEND_ME(reflection_property, setAccessible, arginfo_reflection_property_setAccessible, 0)
    6684             :         PHP_FE_END
    6685             : };
    6686             : 
    6687             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_constant_export, 0, 0, 2)
    6688             :         ZEND_ARG_INFO(0, class)
    6689             :         ZEND_ARG_INFO(0, name)
    6690             :         ZEND_ARG_INFO(0, return)
    6691             : ZEND_END_ARG_INFO()
    6692             : 
    6693             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_constant___construct, 0, 0, 2)
    6694             :         ZEND_ARG_INFO(0, class)
    6695             :         ZEND_ARG_INFO(0, name)
    6696             : ZEND_END_ARG_INFO()
    6697             : 
    6698             : static const zend_function_entry reflection_class_constant_functions[] = {
    6699             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6700             :         ZEND_ME(reflection_class_constant, export, arginfo_reflection_class_constant_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6701             :         ZEND_ME(reflection_class_constant, __construct, arginfo_reflection_class_constant___construct, 0)
    6702             :         ZEND_ME(reflection_class_constant, __toString, arginfo_reflection__void, 0)
    6703             :         ZEND_ME(reflection_class_constant, getName, arginfo_reflection__void, 0)
    6704             :         ZEND_ME(reflection_class_constant, getValue, arginfo_reflection__void, 0)
    6705             :         ZEND_ME(reflection_class_constant, isPublic, arginfo_reflection__void, 0)
    6706             :         ZEND_ME(reflection_class_constant, isPrivate, arginfo_reflection__void, 0)
    6707             :         ZEND_ME(reflection_class_constant, isProtected, arginfo_reflection__void, 0)
    6708             :         ZEND_ME(reflection_class_constant, getModifiers, arginfo_reflection__void, 0)
    6709             :         ZEND_ME(reflection_class_constant, getDeclaringClass, arginfo_reflection__void, 0)
    6710             :         ZEND_ME(reflection_class_constant, getDocComment, arginfo_reflection__void, 0)
    6711             :         PHP_FE_END
    6712             : };
    6713             : 
    6714             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_parameter_export, 0, 0, 2)
    6715             :         ZEND_ARG_INFO(0, function)
    6716             :         ZEND_ARG_INFO(0, parameter)
    6717             :         ZEND_ARG_INFO(0, return)
    6718             : ZEND_END_ARG_INFO()
    6719             : 
    6720             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_parameter___construct, 0)
    6721             :         ZEND_ARG_INFO(0, function)
    6722             :         ZEND_ARG_INFO(0, parameter)
    6723             : ZEND_END_ARG_INFO()
    6724             : 
    6725             : static const zend_function_entry reflection_parameter_functions[] = {
    6726             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6727             :         ZEND_ME(reflection_parameter, export, arginfo_reflection_parameter_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6728             :         ZEND_ME(reflection_parameter, __construct, arginfo_reflection_parameter___construct, 0)
    6729             :         ZEND_ME(reflection_parameter, __toString, arginfo_reflection__void, 0)
    6730             :         ZEND_ME(reflection_parameter, getName, arginfo_reflection__void, 0)
    6731             :         ZEND_ME(reflection_parameter, isPassedByReference, arginfo_reflection__void, 0)
    6732             :         ZEND_ME(reflection_parameter, canBePassedByValue, arginfo_reflection__void, 0)
    6733             :         ZEND_ME(reflection_parameter, getDeclaringFunction, arginfo_reflection__void, 0)
    6734             :         ZEND_ME(reflection_parameter, getDeclaringClass, arginfo_reflection__void, 0)
    6735             :         ZEND_ME(reflection_parameter, getClass, arginfo_reflection__void, 0)
    6736             :         ZEND_ME(reflection_parameter, hasType, arginfo_reflection__void, 0)
    6737             :         ZEND_ME(reflection_parameter, getType, arginfo_reflection__void, 0)
    6738             :         ZEND_ME(reflection_parameter, isArray, arginfo_reflection__void, 0)
    6739             :         ZEND_ME(reflection_parameter, isCallable, arginfo_reflection__void, 0)
    6740             :         ZEND_ME(reflection_parameter, allowsNull, arginfo_reflection__void, 0)
    6741             :         ZEND_ME(reflection_parameter, getPosition, arginfo_reflection__void, 0)
    6742             :         ZEND_ME(reflection_parameter, isOptional, arginfo_reflection__void, 0)
    6743             :         ZEND_ME(reflection_parameter, isDefaultValueAvailable, arginfo_reflection__void, 0)
    6744             :         ZEND_ME(reflection_parameter, getDefaultValue, arginfo_reflection__void, 0)
    6745             :         ZEND_ME(reflection_parameter, isDefaultValueConstant, arginfo_reflection__void, 0)
    6746             :         ZEND_ME(reflection_parameter, getDefaultValueConstantName, arginfo_reflection__void, 0)
    6747             :         ZEND_ME(reflection_parameter, isVariadic, arginfo_reflection__void, 0)
    6748             :         PHP_FE_END
    6749             : };
    6750             : 
    6751             : static const zend_function_entry reflection_type_functions[] = {
    6752             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6753             :         ZEND_ME(reflection_type, allowsNull, arginfo_reflection__void, 0)
    6754             :         ZEND_ME(reflection_type, isBuiltin, arginfo_reflection__void, 0)
    6755             :         ZEND_ME(reflection_type, __toString, arginfo_reflection__void, 0)
    6756             :         PHP_FE_END
    6757             : };
    6758             : 
    6759             : ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_extension_export, 0, 0, 1)
    6760             :         ZEND_ARG_INFO(0, name)
    6761             :         ZEND_ARG_INFO(0, return)
    6762             : ZEND_END_ARG_INFO()
    6763             : 
    6764             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_extension___construct, 0)
    6765             :         ZEND_ARG_INFO(0, name)
    6766             : ZEND_END_ARG_INFO()
    6767             : 
    6768             : static const zend_function_entry reflection_extension_functions[] = {
    6769             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6770             :         ZEND_ME(reflection_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6771             :         ZEND_ME(reflection_extension, __construct, arginfo_reflection_extension___construct, 0)
    6772             :         ZEND_ME(reflection_extension, __toString, arginfo_reflection__void, 0)
    6773             :         ZEND_ME(reflection_extension, getName, arginfo_reflection__void, 0)
    6774             :         ZEND_ME(reflection_extension, getVersion, arginfo_reflection__void, 0)
    6775             :         ZEND_ME(reflection_extension, getFunctions, arginfo_reflection__void, 0)
    6776             :         ZEND_ME(reflection_extension, getConstants, arginfo_reflection__void, 0)
    6777             :         ZEND_ME(reflection_extension, getINIEntries, arginfo_reflection__void, 0)
    6778             :         ZEND_ME(reflection_extension, getClasses, arginfo_reflection__void, 0)
    6779             :         ZEND_ME(reflection_extension, getClassNames, arginfo_reflection__void, 0)
    6780             :         ZEND_ME(reflection_extension, getDependencies, arginfo_reflection__void, 0)
    6781             :         ZEND_ME(reflection_extension, info, arginfo_reflection__void, 0)
    6782             :         ZEND_ME(reflection_extension, isPersistent, arginfo_reflection__void, 0)
    6783             :         ZEND_ME(reflection_extension, isTemporary, arginfo_reflection__void, 0)
    6784             :         PHP_FE_END
    6785             : };
    6786             : 
    6787             : ZEND_BEGIN_ARG_INFO(arginfo_reflection_zend_extension___construct, 0)
    6788             :         ZEND_ARG_INFO(0, name)
    6789             : ZEND_END_ARG_INFO()
    6790             : 
    6791             : static const zend_function_entry reflection_zend_extension_functions[] = {
    6792             :         ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
    6793             :         ZEND_ME(reflection_zend_extension, export, arginfo_reflection_extension_export, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)
    6794             :         ZEND_ME(reflection_zend_extension, __construct, arginfo_reflection_zend_extension___construct, 0)
    6795             :         ZEND_ME(reflection_zend_extension, __toString, arginfo_reflection__void, 0)
    6796             :         ZEND_ME(reflection_zend_extension, getName, arginfo_reflection__void, 0)
    6797             :         ZEND_ME(reflection_zend_extension, getVersion, arginfo_reflection__void, 0)
    6798             :         ZEND_ME(reflection_zend_extension, getAuthor, arginfo_reflection__void, 0)
    6799             :         ZEND_ME(reflection_zend_extension, getURL, arginfo_reflection__void, 0)
    6800             :         ZEND_ME(reflection_zend_extension, getCopyright, arginfo_reflection__void, 0)
    6801             :         PHP_FE_END
    6802             : };
    6803             : /* }}} */
    6804             : 
    6805             : const zend_function_entry reflection_ext_functions[] = { /* {{{ */
    6806             :         PHP_FE_END
    6807             : }; /* }}} */
    6808             : 
    6809             : static zend_object_handlers *zend_std_obj_handlers;
    6810             : 
    6811             : /* {{{ _reflection_write_property */
    6812           5 : static void _reflection_write_property(zval *object, zval *member, zval *value, void **cache_slot)
    6813             : {
    6814          19 :         if ((Z_TYPE_P(member) == IS_STRING)
    6815           5 :                 && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STR_P(member))
    6816          14 :                 && ((Z_STRLEN_P(member) == sizeof("name") - 1  && !memcmp(Z_STRVAL_P(member), "name",  sizeof("name")))
    6817           3 :                         || (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class")))))
    6818             :         {
    6819           4 :                 zend_throw_exception_ex(reflection_exception_ptr, 0,
    6820           4 :                         "Cannot set read-only property %s::$%s", ZSTR_VAL(Z_OBJCE_P(object)->name), Z_STRVAL_P(member));
    6821             :         }
    6822             :         else
    6823             :         {
    6824           3 :                 zend_std_obj_handlers->write_property(object, member, value, cache_slot);
    6825             :         }
    6826           5 : }
    6827             : /* }}} */
    6828             : 
    6829       23504 : PHP_MINIT_FUNCTION(reflection) /* {{{ */
    6830             : {
    6831             :         zend_class_entry _reflection_entry;
    6832             : 
    6833       23504 :         zend_std_obj_handlers = zend_get_std_object_handlers();
    6834       23504 :         memcpy(&reflection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
    6835       23504 :         reflection_object_handlers.offset = XtOffsetOf(reflection_object, zo);
    6836       23504 :         reflection_object_handlers.free_obj = reflection_free_objects_storage;
    6837       23504 :         reflection_object_handlers.clone_obj = NULL;
    6838       23504 :         reflection_object_handlers.write_property = _reflection_write_property;
    6839             : 
    6840       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionException", reflection_exception_functions);
    6841       23504 :         reflection_exception_ptr = zend_register_internal_class_ex(&_reflection_entry, zend_ce_exception);
    6842             : 
    6843       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "Reflection", reflection_functions);
    6844       23504 :         reflection_ptr = zend_register_internal_class(&_reflection_entry);
    6845             : 
    6846       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "Reflector", reflector_functions);
    6847       23504 :         reflector_ptr = zend_register_internal_interface(&_reflection_entry);
    6848             : 
    6849       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunctionAbstract", reflection_function_abstract_functions);
    6850       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6851       23504 :         reflection_function_abstract_ptr = zend_register_internal_class(&_reflection_entry);
    6852       23504 :         zend_class_implements(reflection_function_abstract_ptr, 1, reflector_ptr);
    6853       23504 :         zend_declare_property_string(reflection_function_abstract_ptr, "name", sizeof("name")-1, "", ZEND_ACC_ABSTRACT);
    6854             : 
    6855       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunction", reflection_function_functions);
    6856       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6857       23504 :         reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr);
    6858       23504 :         zend_declare_property_string(reflection_function_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6859             : 
    6860       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED);
    6861             : 
    6862       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionGenerator", reflection_generator_functions);
    6863       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6864       23504 :         reflection_generator_ptr = zend_register_internal_class(&_reflection_entry);
    6865             : 
    6866       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionParameter", reflection_parameter_functions);
    6867       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6868       23504 :         reflection_parameter_ptr = zend_register_internal_class(&_reflection_entry);
    6869       23504 :         zend_class_implements(reflection_parameter_ptr, 1, reflector_ptr);
    6870       23504 :         zend_declare_property_string(reflection_parameter_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6871             : 
    6872       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionType", reflection_type_functions);
    6873       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6874       23504 :         reflection_type_ptr = zend_register_internal_class(&_reflection_entry);
    6875             : 
    6876       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionMethod", reflection_method_functions);
    6877       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6878       23504 :         reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr);
    6879       23504 :         zend_declare_property_string(reflection_method_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6880       23504 :         zend_declare_property_string(reflection_method_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC);
    6881             : 
    6882       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_STATIC", ZEND_ACC_STATIC);
    6883       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PUBLIC", ZEND_ACC_PUBLIC);
    6884       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PROTECTED", ZEND_ACC_PROTECTED);
    6885       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PRIVATE", ZEND_ACC_PRIVATE);
    6886       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_ABSTRACT", ZEND_ACC_ABSTRACT);
    6887       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_FINAL", ZEND_ACC_FINAL);
    6888             : 
    6889       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionClass", reflection_class_functions);
    6890       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6891       23504 :         reflection_class_ptr = zend_register_internal_class(&_reflection_entry);
    6892       23504 :         zend_class_implements(reflection_class_ptr, 1, reflector_ptr);
    6893       23504 :         zend_declare_property_string(reflection_class_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6894             : 
    6895       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS);
    6896       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
    6897       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_FINAL", ZEND_ACC_FINAL);
    6898             : 
    6899       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionObject", reflection_object_functions);
    6900       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6901       23504 :         reflection_object_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_class_ptr);
    6902             : 
    6903       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionProperty", reflection_property_functions);
    6904       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6905       23504 :         reflection_property_ptr = zend_register_internal_class(&_reflection_entry);
    6906       23504 :         zend_class_implements(reflection_property_ptr, 1, reflector_ptr);
    6907       23504 :         zend_declare_property_string(reflection_property_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6908       23504 :         zend_declare_property_string(reflection_property_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC);
    6909             : 
    6910       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionClassConstant", reflection_class_constant_functions);
    6911       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6912       23504 :         reflection_class_constant_ptr = zend_register_internal_class(&_reflection_entry);
    6913       23504 :         zend_class_implements(reflection_class_constant_ptr, 1, reflector_ptr);
    6914       23504 :         zend_declare_property_string(reflection_class_constant_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6915       23504 :         zend_declare_property_string(reflection_class_constant_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC);
    6916             : 
    6917       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_STATIC", ZEND_ACC_STATIC);
    6918       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PUBLIC", ZEND_ACC_PUBLIC);
    6919       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PROTECTED", ZEND_ACC_PROTECTED);
    6920       23504 :         REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PRIVATE", ZEND_ACC_PRIVATE);
    6921             : 
    6922       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionExtension", reflection_extension_functions);
    6923       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6924       23504 :         reflection_extension_ptr = zend_register_internal_class(&_reflection_entry);
    6925       23504 :         zend_class_implements(reflection_extension_ptr, 1, reflector_ptr);
    6926       23504 :         zend_declare_property_string(reflection_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6927             : 
    6928       23504 :         INIT_CLASS_ENTRY(_reflection_entry, "ReflectionZendExtension", reflection_zend_extension_functions);
    6929       23504 :         _reflection_entry.create_object = reflection_objects_new;
    6930       23504 :         reflection_zend_extension_ptr = zend_register_internal_class(&_reflection_entry);
    6931       23504 :         zend_class_implements(reflection_zend_extension_ptr, 1, reflector_ptr);
    6932       23504 :         zend_declare_property_string(reflection_zend_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
    6933             : 
    6934       23504 :         return SUCCESS;
    6935             : } /* }}} */
    6936             : 
    6937         152 : PHP_MINFO_FUNCTION(reflection) /* {{{ */
    6938             : {
    6939         152 :         php_info_print_table_start();
    6940         152 :         php_info_print_table_header(2, "Reflection", "enabled");
    6941             : 
    6942         152 :         php_info_print_table_row(2, "Version", "$Id: ef04ecdb98589f0690abc65e195f0c391448435c $");
    6943             : 
    6944         152 :         php_info_print_table_end();
    6945         152 : } /* }}} */
    6946             : 
    6947             : zend_module_entry reflection_module_entry = { /* {{{ */
    6948             :         STANDARD_MODULE_HEADER,
    6949             :         "Reflection",
    6950             :         reflection_ext_functions,
    6951             :         PHP_MINIT(reflection),
    6952             :         NULL,
    6953             :         NULL,
    6954             :         NULL,
    6955             :         PHP_MINFO(reflection),
    6956             :         PHP_REFLECTION_VERSION,
    6957             :         STANDARD_MODULE_PROPERTIES
    6958             : }; /* }}} */
    6959             : 
    6960             : /*
    6961             :  * Local variables:
    6962             :  * tab-width: 4
    6963             :  * c-basic-offset: 4
    6964             :  * indent-tabs-mode: t
    6965             :  * End:
    6966             :  * vim600: noet sw=4 ts=4 fdm=marker
    6967             :  */

Generated by: LCOV version 1.10

Generated at Wed, 24 Aug 2016 12:20:28 +0000 (32 hours ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.