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

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:14 +0000 (2 days ago)

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