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: 2308 2605 88.6 %
Date: 2014-07-21 Functions: 195 208 93.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:17 +0000 (3 days ago)

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