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: 2281 2588 88.1 %
Date: 2014-10-22 Functions: 195 208 93.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:56 +0000 (14 hours ago)

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