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

Generated by: LCOV version 1.10

Generated at Tue, 27 Sep 2016 10:26:05 +0000 (2 days ago)

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