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

Generated by: LCOV version 1.10

Generated at Sat, 25 Jun 2016 07:09:03 +0000 (4 days ago)

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