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: 2280 2587 88.1 %
Date: 2014-11-22 Functions: 195 208 93.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:22 +0000 (4 days ago)

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