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

Generated by: LCOV version 1.10

Generated at Wed, 20 Jul 2016 02:56:26 +0000 (5 days ago)

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