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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:20 +0000 (8 days ago)

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